Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active October 24, 2018 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/cd18397649a18f9f2ef95238c22cbf45 to your computer and use it in GitHub Desktop.
Save billerickson/cd18397649a18f9f2ef95238c22cbf45 to your computer and use it in GitHub Desktop.
<?php
/**
* Related Posts
* @see https://www.billerickson.net/related-posts-with-searchwp/
*
*/
function be_related_posts() {
$related = ea_get_related_posts( 3 );
if( empty( $related ) )
return;
$loop = new WP_Query( array(
'post__in' => $related,
'orderby' => 'post__in',
) );
if( $loop->have_posts() ):
echo '<section class="related-posts">';
echo '<h3>Related Posts</h3>';
while( $loop->have_posts() ): $loop->the_post();
get_template_part( 'partials/archive', 'related' );
endwhile;
echo '</section>';
endif;
wp_reset_postdata();
}
add_action( 'genesis_after_entry', 'be_related_posts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment