I’m trying to remove posts with a post_parent from a template page on my site. I was able to keep them from displaying in the loop with:
if (have_posts()) : while (have_posts()) : the_post();
if (($post->post_parent) ) {
continue;
} else {
//code to display post
}
The problem is that the pagination is still showing up on pages because there’s still more posts in the query than my posts per page. This causes many blank pages in pagination.
I’ve tried variations of:
function exclude_children( $query ) {
$query->set('post_parent', 0 );
}
add_action( 'pre_get_posts', 'exclude_children' );
And:
$where .= ' AND post_parent = 0';
Before the query_posts() command on my loop template to no avail.
Try this: