Topic: exclude category | WP Masonry Layout

exclude category

Home Forums Lite Version exclude category

This topic contains 14 replies, has 4 voices, and was last updated by  Masonry Guy 5 months, 2 weeks ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #4857 Reply

    Olly

    I am using the plugin to display some posts that have multiple categories. How can i exclude a specific category using the shortcode?

    #4868 Reply

    Masonry Guy
    Keymaster

    Hi Olly,

    Removing post of specific category is not possible yet. We are soon going to add that in our plugin. But it is going to take some time.

    Thanks

    #10185 Reply

    Ricardo Pedrosa

    Hi,

    Any update on this? It would be extremely useful.

    Thanks!

    #10194 Reply

    Masonry Guy
    Keymaster

    Hi Ricardo,

    It is now available in our Pro version. There we have added Custom query box where you can exclude the category from cat id.

    Thanks

    #11773 Reply

    Anita
    Participant

    Hi,

    I tried to exclude a category by adding a custom query, but it is not working for me. What am I doing wrong? I added this code to the custom query box:

    $query->set(‘cat’,’-38′)

    where 38 is the category ID. I am using Genesis with Centric Pro child theme.

    Thanks for your support!

    #11789 Reply

    Masonry Guy
    Keymaster

    Hi Anita,

    You just need to set cat=-38. Can you please try this ?

    Thanks

    #11791 Reply

    Anita

    It works! Thanks for the quick reply.

    #19055 Reply

    Lee Rennie
    Participant

    I’m trying to do the same with a WooCommerce product category. This is my code:

    product_cat=-105

    However it completely stops the search from working – there are no results and all I see is the little loading square. If I remove the code all products appear in the search.

    Help!

    #19073 Reply

    Lee Rennie
    Participant

    Any news on this? I have a client website due to go live and I can’t exclude a product category for the search.

    #19074 Reply

    Masonry Guy
    Keymaster

    Hi Lee,

    For custom post type and taxonomy (product category), you need to write complex query using the filter. Please keep this in your functions.php file and this should fix the issue.

    add_filter('wmlp_query', 'my_custom_query_wmlp',10,2);
    function my_custom_query_wmlp($args, $shortcodeID){
      if ($shortcodeID == #){ // HERE # is shortcode ID
        $args['tax_query'] = array(array(
                   'taxonomy' => 'product_cat',
                   'field'   => 'slug',
                   'terms'   => 'YOUR_CATEGORY_SLUG_HERE',
                   'operator' => 'NOT IN'
               ));
        return $args;
      }
    }

    Thanks

    #19080 Reply

    Lee Rennie
    Participant

    Thanks! This worked great. Just one more thing, when there are no results, instead of a message coming up to say that, all I get is the little square loading gif – this looks like something is happening rather than the fact there are no results. Is there a way for a message to appear when there are no results?

    #19100 Reply

    Lee Rennie
    Participant

    I’ve just realised that the code you gave me has stopped the WP Masonry grids elsewhere on the site aren’t working anymore. All I get is the square loading icon.

    When I remove the code from the functions.php file they start working again. Here’s the code I’m using:

    //Remove sold category from search
    add_filter(‘wmlp_query’, ‘my_custom_query_wmlp’,10,2);
    function my_custom_query_wmlp($args, $shortcodeID){
    if ($shortcodeID == 2){ // HERE # is shortcode ID
    $args[‘tax_query’] = array(array(
    ‘taxonomy’ => ‘product_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘sold’,
    ‘operator’ => ‘NOT IN’
    ));
    return $args;
    }
    }

    I need to get this site live tomorrow, so I’d appreciate your help with this asap!!

    Also, I didn’t hear back from you regarding the ‘no results’ message when there are no results from the search.

    Thanks

    #19107 Reply

    Masonry Guy
    Keymaster

    Hi Lee,

    Can you please try this ?

    //Remove sold category from search
    add_filter(‘wmlp_query’, ‘my_custom_query_wmlp’,10,2);
    function my_custom_query_wmlp($args, $shortcodeID){
    if ($shortcodeID == 2){ // HERE # is shortcode ID
    $args[‘tax_query’] = array(array(
    ‘taxonomy’ => ‘product_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘sold’,
    ‘operator’ => ‘NOT IN’
    ));
    }
    return $args;
    }

    Regarding the no result. We don’t have that currently. We forget to add that and no client ask for that yet. We will try to add in next release.

    Thanks

    #19113 Reply

    Lee Rennie
    Participant

    This works! Amazing, thank you.

    It would be great if you could add the ‘no results’ message in the next release, as it really does look like the search is still running right now even though there aren’t any results.

    Thanks

    #19126 Reply

    Masonry Guy
    Keymaster

    Hi Lee,

    Ya i agree on that. I will start working for it soon.

    Thanks

Viewing 15 posts - 1 through 15 (of 15 total)
Reply To: exclude category
Your information: