• Resolved Argentum

    (@argentum)


    Hi!

    Very nifty plugin. I wonder, if I want to show only pages that belong to two categories (AND) how would I write the shortcode? Seems the category=”cat1,cat2″ shows pages what belong to either (OR). Any hints appreciated. I’ve read on the demo site but I am still not sure how to.

    Best regards

Viewing 15 replies - 1 through 15 (of 20 total)
  • Thread Starter Argentum

    (@argentum)

    Wrong edit. Sorry.

    • This reply was modified 8 years, 11 months ago by Argentum.
    Plugin Author Darren Cooney

    (@dcooney)

    No worries. You got this sorted?

    Thread Starter Argentum

    (@argentum)

    No, I am still wondering how! 🙂

    Plugin Author Darren Cooney

    (@dcooney)

    Ok, no worries.
    Yea, you can’t do this with the shortcode because ALM uses the category_name WP_Query parameter which uses OR as you found out.

    The only way I can suggest is you try to make use of this filter to modify the query.

    function my_cat_listing($args){
     
      $args['category__and'] = array(
          array( 2, 6 )
      );
      return $args;
     
    }
    add_filter( 'alm_query_args_{your_alm_ID}', 'my_cat_listing' ); // <- Change this to be your ID
    Thread Starter Argentum

    (@argentum)

    OK, thanks! I will give it a spin later. 🙂

    Yes. This is a big feature request for me. Is there any chance that this is coming soon?

    Plugin Author Darren Cooney

    (@dcooney)

    @peretz – did you try the example I shared above?

    @dcooney – I haven’t. Where exactly do I find the code that needs to be modified?
    Thanks.

    Plugin Author Darren Cooney

    (@dcooney)

    @peretz – The code I posted is a filter you can use to adjust query params. I also pointed a link to the docs.

    Thread Starter Argentum

    (@argentum)

    Hm, can’t see that the function is doing anything. Still showing pages that only belong to category id 76, i want to load pages that belong to 76 AND 67. The Shortcode looks like this.

    
    [ajax_load_more id="lyxdam" preloaded="true" category="dam,lyx" exclude="47" posts_per_page="5" repeater="default" post_type="page" pause="true" transition="fade" images_loaded="false" button_label="Visa fler" button_loading_label="Laddar..." container_type="div" css_classes="flexbox"]
    

    and the code I added to functions.php

    
    function my_lyxdam_listing($args){
     
      $args['category__and'] = array(
          array(76,67)
      );
      return $args;
     
    }
    add_filter( 'alm_query_args_{lyxdam}', 'my_lyxdam_listing' );
    

    What am I doing wrong here? Quotation marks missing anywhere?

    Thread Starter Argentum

    (@argentum)

    Ah, darn wait. There is a category in the shortcode!

    @dcooney – okay. I clicked on that link which explains exactly how to do this. And I will give it a try. Thank you for your time!

    Thread Starter Argentum

    (@argentum)

    Nope. It loads all pages in the site now. 😀

    
    [ajax_load_more id="lyxdam" preloaded="true" exclude="47" posts_per_page="5" repeater="default" post_type="page" pause="true" transition="fade" images_loaded="false" button_label="Visa fler" button_loading_label="Laddar..." container_type="div" css_classes="flexbox"]
    
    Plugin Author Darren Cooney

    (@dcooney)

    What filter did you use?

    Plugin Author Darren Cooney

    (@dcooney)

    Ok sorry,
    I posted the incorrect filter markup.

    I just tested this example and it works.

    function my_cat_listing($args){ 
      $args['category__and'] = array( 1, 33 );
      return $args; 
    }
    add_filter( 'alm_query_args_12345', 'my_cat_listing' ); // <- Change this to be your ID
Viewing 15 replies - 1 through 15 (of 20 total)

The topic ‘Category parameter with AND’ is closed to new replies.