If you have troubles since the update to WordPress 4.5 please read this post before opening a new thread.
Tagged: related posts
i’ve got two questions about the related-posts-function on post-pages:
1) I would like to exclude two categories from the Related-Posts-Slider. How can I do so?
2) The Related-Post-Function does not work on all posts.
If a post got:
no Tag -> no Related Posts (that’s normal for the moment. But probably it is possible to show any post randomly?)
one Tag -Y sometimes related Posts / sometimes not
more tags -> always Related Posts.
What can I do?
To exclude categories, open includes > related-posts.php. Find this code.
$my_query = new WP_Query("tag=$tag_ids&showposts=$postcount&ignore_sticky_posts=1&orderby=rand");
Add exclude category. Find the category ID to be excluded.
$my_query = new WP_Query("tag=$tag_ids&showposts=$postcount&ignore_sticky_posts=1&orderby=rand&cat=-12,-34,-56");
Thanks Ismael! I will try that soon. Can you also say something about my second question?
I wrote stupid things. I want to exclude tags not categories. Therefore I changed your code to this:
$my_query = new WP_Query(“tag=$tag_ids&showposts=$postcount&ignore_sticky_posts=1&orderby=rand&tags=-59,-61,-62”);
But that doesn’t really help. Any Ideas?
Try this. All posts without the tag ID 59, 61 and 62 will not be included.
WP_Query("tag=$tag_ids&showposts=$postcount&ignore_sticky_posts=1&orderby=rand&tag__not_in => array( 59, 61, 62 )");
does it mean: All posts WITH this Tag-IDs will be Excludet or All posts WITHOUT this Tag-IDs will be excluded (that’s what i understood now).
I whant to exclude this three Tag-IDs from the related posts.
Sorry for interrupting you again!
The topic ‘Exclude Category from Related Posts’ is closed to new replies.