• Hi TC.K,

    I am trying to have the ajax results show up in random order.
    Here is what I have tried…

    add_filter('uwpqsf_query_args','injecting_custom_arg','', 4);
    function injecting_custom_arg($args, $id,$getdata){
    //$getdata is like $_GET or $_POST, so you can use it to get the value from instructor.
        if($id == '122') {
            $args['orderby'] = 'rand';
        }
        return $args;
    }

    I want to specifically target one of the forms created with the plugin (ID: 122).
    Please help me. Thanks in advance.

    https://wordpress.org/plugins/ultimate-wp-query-search-filter/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author TC.K

    (@wp_dummy)

    You can configure the order setting in the form setting page -> Result Page Settings.

    I also use the ajax method with a custom result layout.

    But when I change the Orderby at the Result Page Settings nothing happens. It keeps showing the oldest post first. Ascending and Descending also does not change anything.

    Thread Starter serks

    (@serks)

    Yes, I can also verify that using the settings in the form settings page does not work.
    Both orderby and ascending/descending settings have no effect.

    I had already tried those settings before I created this topic but I just assumed that these settings were only for the default search template and not for ajax which is why I didn’t mention it earlier.

    Any other ideas?
    Thanks for quick response.

    Thread Starter serks

    (@serks)

    Ok I have found my problem…
    I was using the following code on my site to reorder the custom post type in my admin.

    add_filter("posts_orderby", "reorder_cpt", 10, 2);
    function reorder_cpt($orderby, &$query){
        global $wpdb;
        //figure out whether you want to change the order
        if (get_query_var("post_type") == "custom_post_type") {
             return "$wpdb->posts.post_title ASC";
        }
        return $orderby;
    }

    Turns out it was messing with the entire site and not just the admin listings.

    I can now confirm that changing the order settings in the Results Page Settings of the WPQSF form does indeed work as it should.

    Yasp0, take a look to see if you have any other functions elsewhere in your code that could be messing with the query’s order.

    Thanks

    Thanks, also found my problem 🙂

    I had a query for an advanced search in the functions.php which caused it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘AJAX result in random order not working’ is closed to new replies.