-
AuthorPosts
-
January 8, 2019 at 12:28 pm #1051356
I created a page and I am adding blog posts and I can’t exclude categories.
I have posts in the category “food” and “meat”.
I have posts in the category “food” and “fruit”.
I want to exclude meat, but as they have “food” as well, they are appearing.
How to exclude “meat” even it it has “food” category?
Thank you.
January 10, 2019 at 6:54 am #1052194Hey peterolle,
Thank you for using Enfold.
Are you using the grid layout? Have you tried to unselect the “food” category and leave the “fruit” category selected from the blog posts element? Please provide a link to the actual page with the blog posts element.
Best regards,
IsmaelJanuary 10, 2019 at 8:49 am #1052240No, I am using 1 author with big image.
Have you tried to unselect the “food” category and leave the “fruit” category selected from the blog posts element?
No, this is an example with 2 categories, not my live site with thousands of posts and hundreds of categories. What you suggest is not possible and it is not excluding the category.
I selected all the categories but the one I want to exclude.
I am doing this locally, so I cant share a link, but you can test this in 1 minute creating 3 posts with those category and see how it is not working.
Please let me know how to exclude the categories I need to.
Thank you.
January 11, 2019 at 12:47 pm #1052728Anything about this?
January 14, 2019 at 12:19 am #1053460Hi,
I selected all the categories but the one I want to exclude.
Did you select the parent categories? It should display only the items from the selected category unless the parent category of the child categories where the posts belong to are selected.
Best regards,
IsmaelJanuary 14, 2019 at 9:38 am #1053582There are no parent categories. Those are posts with more than one category as I explained in the first post.
I want to exclude “meat”, but as they have “food” as well, they are appearing. I cant exclude food as well, I need those posts to appear.
I want to exclude “meat” only.
How ?
January 15, 2019 at 12:27 am #1053884Hi,
Thanks for the update. This filter might help:
// exclude meat add_filter('avia_blog_post_query', 'avia_blog_post_query_mod', 10, 2); function avia_blog_post_query_mod($query, $params) { $query['tax_query'][] = [ 'taxonomy' => 'category', 'field' => 'name', 'terms' => 'meat', 'operator' => 'NOT IN', ]; return $query; }
// https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
Best regards,
IsmaelJanuary 15, 2019 at 9:28 am #1054011I see that this will disable them in al blog posts that exist and that is a problem, I need to hide them in homepage only, but I have other pages that I need them to appear.
How can I do the same, by page ID and algo hiding more than 1 category?
Thank you.
January 17, 2019 at 6:18 am #1054872Hi,
You can use the is_page conditional function if you want this modification applied to a specific page. And change the value “meat” to an array if you need to exclude multiple categories.
Best regards,
IsmaelJanuary 18, 2019 at 10:48 am #1055390Thank you Ismael. Please share the code for that.
I have my homepage “page 1” with some things and last 10 blog posts. (I want to hide here the category)
Under those last 10 blog posts I have a button “see all blog posts” that goes to another page “page 2”. (I want to show the category there, but hide others)So I need an example code that hides from page 1 the categories I want and the same for page 2. But only per page, if I hide in page 1 “category1 and category2”, those should be visible in page 2, unless I hide them as well.
Thank you.
January 22, 2019 at 4:37 am #1057013Hi,
The code should look something like this:
// exclude categories add_filter( 'avia_blog_post_query', 'avia_blog_post_query_mod', 10, 2 ); function avia_blog_post_query_mod($query, $params) { if( is_page('home') ) { // exclude meat category when the current page is "home" $query['tax_query'][] = [ 'taxonomy' => 'category', 'field' => 'name', 'terms' => 'meat', 'operator' => 'NOT IN', ]; } if( is_page('fish') ) { // exclude an array of categories on the "fish" page $query['tax_query'][] = [ 'taxonomy' => 'category', 'field' => 'name', 'terms' => array('meat', 'vegetables', 'fruits'), 'operator' => 'NOT IN', ]; } return $query; }
Refer to the documentation for more info:
// https://developer.wordpress.org/reference/functions/is_page/
// https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_ParametersBest regards,
IsmaelApril 1, 2019 at 6:17 am #1085278I just tested this and it is not working.
// exclude categories add_filter( 'avia_blog_post_query', 'avia_blog_post_query_mod', 10, 2 ); function avia_blog_post_query_mod($query, $params) { if( is_page('home') ) { // exclude testing category when the current page is "home" $query['tax_query'][] = [ 'taxonomy' => 'category', 'field' => 'name', 'terms' => 'testing', 'operator' => 'NOT IN', ]; } return $query; }
It seems that
if( is_page('home') ) {
is doing nothing.Thank you.
- This reply was modified 5 years, 7 months ago by peterolle.
April 2, 2019 at 12:12 am #1085751Hi,
Thanks for the update.
Is “home” the actual slug or name of your home/front page? Try is_home instead of is_page or use the actual name or id of your home page.
Best regards,
IsmaelSeptember 3, 2020 at 10:41 pm #1243170Hei, i need something similar:
I added hierarchy to my blog posts in a custom post type.
Now I only want to show the items of the first hierarchy? Is this possible
September 7, 2020 at 6:26 pm #1244045Hi hunter74,
Unfortunately, it would require quite some time and customization of the theme to achieve this, so I am sorry to tell you that this is not covered by our support. However, if it’s really important for you to get this done, you can always hire a freelancer to do the job for you :)
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.