• Resolved taikodig

    (@taikodig)


    I interested if it possible in shortcode like [adverts_list category=”133″] show several categories? I tried to use it with coma, like here [adverts_list category=”133,138″] but it show only one last category-

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

    (@gwin)

    Hi,
    right now by default the “category” param supports only single category, but please post here in the middle of next week i will be then back in the office and will be able to post here a code snippet which will allow multiple categories.

    Thread Starter taikodig

    (@taikodig)

    ok, I will write ypu on Wednesday, thank you

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    you can add the code below in your theme functions.php file (or even better create a new WP plugin and add it there)

    
    add_filter( "shortcode_atts_adverts_list", "adverts_list_search_by_multi_category_atts", 10, 3 );
    add_filter( "adverts_list_query", "adverts_list_search_by_multi_category_param", 10, 2 );
    function adverts_list_search_by_multi_category_atts( $out, $pairs, $att ) {
        $out["_multicat"] = "";
        if(isset($att["_multicat"])) {
            $out["_multicat"] = $att["_multicat"];
        }
        return $out;
    }
    function adverts_list_search_by_multi_category_param($args, $params) {
        if(!empty($params["_multicat"])) {
            if(!is_array($args["tax_query"])) {
                $args["tax_query"] = array();
            }
            $args["tax_query"][] = array(
                'taxonomy' => 'advert_category',
                'field'    => 'term_id',
                'terms'    => array_map( "trim", explode( ",", $params["_multicat"])),
            );
        }
        return $args;
    }
    

    Once you do that you can use the [adverts_list] as

    
    [adverts_list _multicat="133,138"]
    

    Then the [adverts_list] will show Ads which are in category with ID 133 or 138.

    Thread Starter taikodig

    (@taikodig)

    thank you. Now is working good

    Plugin Author Greg Winiarski

    (@gwin)

    Ok great, i am marking this thread as resolved then :).

    BTW. If you are finding the plugin useful i would be thankful if you could write a short one or two sentence review here https://ww.wp.xz.cn/support/view/plugin-reviews/wpadverts

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

The topic ‘Several categories’ is closed to new replies.