Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active July 23, 2020 20:22
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/6bfe300ba9c5a0d4a5ae910e6d54b135 to your computer and use it in GitHub Desktop.
Save billerickson/6bfe300ba9c5a0d4a5ae910e6d54b135 to your computer and use it in GitHub Desktop.
<?php
/**
* Single
*
* @package EAGenesisChild
* @author Bill Erickson
* @since 1.0.0
* @license GPL-2.0+
**/
/**
* Related Posts
*
*/
function ea_single_related_posts() {
$loop = new WP_Query( array(
'posts_per_page' => 3,
'post__not_in' => array( get_the_ID() ),
'category_name' => ea_first_term( 'category', 'slug' )
) );
if( $loop->have_posts() ):
echo '<section class="related-posts">';
echo '<header><h3>Related Posts</h3></header>';
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', 'ea_single_related_posts', 5 );
genesis();
@bathrivijay05
Copy link

I added the above code in my EA Genesis Child Theme's single.php file. It shows the following error.
Warning: urlencode() expects parameter 1 to be string, object given in F:\Do Not Delete\LOCALHOST\htdocs\wp\wp-includes\formatting.php on line 5371

@billerickson
Copy link
Author

I don't see the urlencode() function in the above code snippet so I don't believe it is responsible for the error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment