• Resolved moacirsantana

    (@moacirsantana)


    Hello! I have both a custom wordpress query as to show the ads and the shortcode you provide:

    [adverts_list search_bar="disabled" list_type="all" show_pagination="0" posts_per_page="6" order_by="rand"]

    I want it to display all ads randomly, with featured ads on top while the other ones are mixed up.

    So if there’s anything I should add to the shortcode, or a specific wordpress query parameter, I’d be grateful.

    I’ve already added the ‘random’ functionality, all I need now is a guidance as to get the featured ads on top working.

    Thank you!

    • This topic was modified 5 years, 4 months ago by moacirsantana.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    to show the Featured Ads always on top you would need to include sorting by “is_featured” flag in the “orderby” clause.

    One way to do that is to make the custom sorting function look like this

    
    add_filter( "adverts_list_query", function( $args, $params ) {
        if( isset( $params["order_by"] ) && $params["order_by"] == "rand" ) {
            $args["orderby"] = array( "menu_order" => "DESC", "rand" => "DESC" );
        }
        return $args;
    }, 10, 2 );
    

    Before adding this function in functions.php file remove the old code which sorts by “rand”.

    Thread Starter moacirsantana

    (@moacirsantana)

    Thanks Greg, it works perfectly

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Featured ads always on top’ is closed to new replies.