• Resolved NeiltheSpacechimp

    (@neilthespacechimp)


    I’d like to randomise the advertisement order. I’d like a shortcode that does this –

    [adverts_list order_by=”rand-asc”]

    Is there a filter I can add to the theme? I have all the premium plugins if that helps. Thanks

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

    (@gwin)

    Hi,
    if you add the code below in your theme functions.php file

    
    add_filter( "adverts_list_query", function( $args, $params ) {
        if( $params["order_by"] == "rand-asc" ) {
            $args["orderby"] = "rand";
        }
        return $args;
    }, 10, 2 );
    

    Then you should be able to use the adverts list as

    
    [adverts_list order_by="rand-asc" switch_views="0"]
    

    Note that right now when using custom sorting you need to also switch_views param set to 0, as the custom sorting will not be properly selected.

    Thread Starter NeiltheSpacechimp

    (@neilthespacechimp)

    Awesome, thank you Greg. That was a really quick response. I’ll try it out in a moment.

    Thread Starter NeiltheSpacechimp

    (@neilthespacechimp)

    Hi Greg,
    That seems to have worked well. Thank you very much.

    Small note however with pagination the results are randomised on each page of results which means that some results will appear twice and other may not appear at all.

    for me personally this won’t be an issue as I want all results visible on the main advert page and have set posts per page to 9999999. But if someone else wants to use this with pagination then they may need modify the above code slightly.

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    the order is randomized on every page load regardless of page number the best you can do is disable the pagination with show_pagination='0' param.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Order of advertisments’ is closed to new replies.