Support » Plugin: WPAdverts - Classifieds Plugin » Display listings with two categories

  • Resolved ncovello


    Is there a way to display listings which have both categories?
    Listing A
    Categories: Cosmétique + Mobilier

    Listing B
    Categories: Mobilier

    We want to show only Listing A (that has both Cosmétique and Mobilier categories)

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Greg Winiarski


    i am not sure where you would like to display it and how? Do you want to have an [adverts_list] shortcode which will show only ads assigned to Cosmétique + Mobilier categories if not then what you would like to do?



    Yes, I want the shortcode [adverts_list] with both categories, but to only show the adverts that have both categories.
    Because if I use: [adverts_list category=”1,2″] it will show the adverts with category 1 and/OR category 2, but we need to show adverts with both category 1 AND category 2.

    This is because we have 5 main categories and 4 categories that specific a product type. And we don’t want to use ‘parent’ ‘child’ categories, because

    Plugin Author Greg Winiarski


    You should be able to change the category search from one-or-more to “all” by adding the code below in your theme functions.php file

    add_filter( "adverts_list_query", function( $args ) {
      if( isset( $args["tax_query"][0] ) && $args["tax_query"][0]["taxonomy"] == "advert_category" ) {
        $args["tax_query"][0]["terms"] = explode( ",", $args["tax_query"][0]["terms"] );
        $args["tax_query"][0]["operator"] = "AND";
        $args["tax_query"][0]["include_children"] = false;
      return $args;
    } );

    Then using [adverts_list category="1,2″] shortcode will return only Ads assigned to both category #1 and #2.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display listings with two categories’ is closed to new replies.