• Hello,

    Please can you add a new parameter to the [adverts_list] shortcode which is ability to exclude specific categories

    E.g

    exclude_category: – allows excluding specific ads categories from the advert list

    Thanks

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

    (@gwin)

    Hi,
    you can do that by adding the code below in your theme functions.php file or even better by creating a new blank plugin and pasting the below code there

    
    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;
    }
    

    Once you do that you should be able to use the [adverts_list] as [adverts_list _category_exclude="100"] where 100 is the ID of the category you want to exclude.

Viewing 1 replies (of 1 total)
  • The topic ‘New parameter feature request’ is closed to new replies.