• Resolved Copy

    (@copyinsert9911)


    Hello,

    I have 3 categories on my ads site. And currently [adverts_list] shows a list of ads from all 3 categories.

    How do I change this to show ads from 2 categories only?

    I tried this [adverts_list _exclude_category=”52″] and it didn’t work.
    Is there some other way where I can list ads from only 2 selected categories?

    Thanks.

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

    (@gwin)

    Hi,
    by default we do not have such feature i am afraid, however you can add in your theme functions.php file the code below

    
    add_filter( 'shortcode_atts_adverts_list', 'my_adverts_list_category_exclude_atts', 10, 3 );
    function my_adverts_list_category_exclude_atts( $out, $pairs, $atts ) {
        if( ! isset( $atts["_category_exclude"] ) ) {
            $atts["_category_exclude"] = null;
        }
        
        $out["_category_exclude"] = $atts["_category_exclude"];
        return $out;
    }
    add_filter( "adverts_list_query", "my_adverts_list_category_exclude", 10, 2 );
    function my_adverts_list_category_exclude( $args, $params ) {
        if( isset( $params["_category_exclude"] ) ) {
            if( ! isset( $args["taxonomy"] ) || ! is_array( $args["taxonomy"] ) ) {
                $args["tax_query"] = array();
            }
            $args["tax_query"][] = array(
                'taxonomy' => 'advert_category',
                'field'    => 'term_id',
                'terms'    => $params["_category_exclude"],
                'operator' => 'NOT IN',
    	    );
        }
        return $args;
    }
    

    It will allow you to use the [adverts_list] with _category_exclude param like this

    
    [adverts_list _category_exclude="52"]
    
    Thread Starter Copy

    (@copyinsert9911)

    Nice, this is working. Thanks Greg.

    Cheers.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Exclude one category from adverts_list’ is closed to new replies.