How to Exempt Trending Posts from still Displaying on Latest Posts

Overview Of: How to Exempt Trending Posts from still Displaying on Latest Posts


Pedro By
Web & SEO Tutorials
5
(2)


images-3
If you have Trending category where trending posts are featured, you’ll notice they still appear under latest post, thereby creating duplication. Well, all you have to do is apply this code and it’s done.

Go to functions.php, edit it and put this code at the bottom. Change my category ID from 6 to the category ID of your Trending category.

<?php function exclude_posts_from_specific_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'category__not_in', '6' );
    }
}
add_action( 'pre_get_posts', 'exclude_posts_from_specific_category' );
?>

This function would prevent Trending posts from still displaying under the latest posts. Avoid duplication.

To get a category ID, edit the category via admin dashboard and view your browser bar. That’s it. See screenshot

Screenshot-20200610-134338-Chrome-Beta

Average rating 5 / 5. Vote count: 2

No votes so far! Be the first to rate this post.

Spread the love

Published: 1 month ago | 1 comment

✏️ Create Topic

Subscribe
Notify of
guest
1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
YunusaMG
Member
June 14, 2020 11:23 pm

Thanks so much boss

1
0
Would love your thoughts, please comment.x
()
x
1
0
Would love your thoughts, please comment.x
()
x