Hello, I started but I think I found a solution for you, tests category_id = “- 52”
52 is your ID you add the least as in the example.
By cons me my problem is that I want to do that with several IDs for several categories but it does not work.
How to do?
If you would like to exclude multiple categories, it’s best to use a taxonomy query (tutorial).
[display-posts taxonomy=”category” tax_term=”category-1, category-2″ tax_operator=”NOT IN”]
Thread Starter
artkom
(@artkom)
Yes it’s not working when I’m tryind to show posts per ID’s (not categories ID)
Still not working (
Can you provide the specific shortcode you’re using that doesn’t work?
Thanks
I succeeded thank you here is my code:[display-posts taxonomy=”category” tax_term=”patrice, pierre, ladislas” tax_operator=”NOT IN” category=”LUDOTEK” posts_per_page=”200″]
http://soludik.fr/liste-ludotheque/
-
This reply was modified 7 years, 1 month ago by
darnethil.
Thread Starter
artkom
(@artkom)
Here is an example of my shortcode: [display-posts id="5982, 7072, 5542, 31" image_size="thumbnail" exclude_current="true"]
The code above is showing only the one post (31). It belongs to the category “vendors”.
All other posts are not showing (5982, 7072, 5542). These posts are from the “industry” category that was excluded from the main page with exclude_category() function
I hope it’ll help to sort it out… Please let me know if you need any other information. Thank you
Can you share the exclude category function? My guess is it’s excluding those posts from all custom queries (like Display Posts) as well.
Thread Starter
artkom
(@artkom)
Sorry for the delay. Sure here is it:
function exclude_category( $query ) {
if ( $query->is_home() ) {
$query->set( 'cat', '-135' );
}
if ( $query->is_category ) {
$queried_object = get_queried_object();
$child_cats = (array) get_term_children( $queried_object->term_id, 'category' );
if ( ! $query->is_admin )
//exclude the posts in child categories
$query->set( 'category__not_in', array_merge( $child_cats ) );
}
return $query;
}
Thread Starter
artkom
(@artkom)
$query->set( 'cat', '-135' );
This is an id of excluded category. And I want to use post ID’s (NOT category id) for shortcode.
Thank you
Yes, that’s the issue right there. Your exclude_category() function affects every query on the site. You need to limit it to the main query using $query->is_main_query().
Here’s more information: https://www.billerickson.net/customize-the-wordpress-query/
Thread Starter
artkom
(@artkom)
Yes, this is the solution.
The post can be closed as resolved.
Thank you so much!