• Resolved transeffect

    (@transeffect)


    With all the raving reviews I see of this plugin, I’m surprised no one has mentioned the inability to sort [adverts_list] output.

    My client wanted to display ads sorted by title. I’m not sure how to accomplish this without changing the core code. Any idea?

    For anyone else who might want this functionality:

    1. Open wp-content/plugins/wpadverts/includes/shortcodes.php
    2. Scroll to line 145
    3. Change line 145 so it sorts the way you want.

    For instance, I wanted to sort by title in alphabetical order, so I changed line 145 from:

    'orderby' => array( 'menu_order' => 'DESC', 'date' => 'DESC' )

    to

    'orderby' => array( 'title' => 'ASC', 'menu_order' => 'DESC', 'date' => 'DESC' )

    This way, it sorts preferentially by title, then by menu order descending (newest first), then by date descending (newest first).

    ** Note: if you use this method to change the way items sort, your change will be overwritten every time you update the plugin, so you’ll have to make the change again. **

    https://ww.wp.xz.cn/plugins/wpadverts/

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

    (@gwin)

    Hi, i do have a similar plugin like WPAdverts as well and sorting by title is actually quite rare. Either way in WPAdverts you can add such functionality without modifying original source code.

    In your theme functions.php file add following code (or you can create a new plugin and paste the code there):

    add_filter( "adverts_list_query", "my_adverts_sort_by_title" );
    function my_adverts_sort_by_title( $args ) {
        $args["orderby"] = array( 'title' => 'ASC', 'menu_order' => 'DESC', 'date' => 'DESC' );
        return $args;
    }

    How do you change it so the sort order is random every time ?

    I am thinking of using this plugin – but I need to be able to randomise every time. Otherwise the first listing will be displayed each time

    Plugin Author Greg Winiarski

    (@gwin)

    Try adding this code to your theme functions.php it will display ads always in random order

    add_filter( "adverts_list_query", "my_adverts_sort_by_rand" );
    function my_adverts_sort_by_rand( $args ) {
        $args["orderby"] = 'rand';
        return $args;
    }

    I guess that with random order pagination will be problematic so you would need to have all ads on one page.

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

The topic ‘Sort adverts by title’ is closed to new replies.