Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #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.

    #1052194

    Hey 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,
    Ismael

    #1052240

    No, 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.

    #1052728

    Anything about this?

    #1053460

    Hi,

    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,
    Ismael

    #1053582

    There 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 ?

    #1053884

    Hi,

    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,
    Ismael

    #1054011

    I 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.

    #1054872

    Hi,

    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,
    Ismael

    #1055390

    Thank 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.

    #1057013

    Hi,

    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_Parameters

    Best regards,
    Ismael

    #1085278

    I 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, 8 months ago by peterolle.
    #1085751

    Hi,

    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,
    Ismael

    #1243170

    Hei, 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

    #1244045

    Hi 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

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.