-
-
Save billerickson/cd18397649a18f9f2ef95238c22cbf45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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