Meta sort order

Forums › Forums › Search & Filter Pro › Meta sort order

Viewing 8 posts – 1 through 8 (of 8 total)
  • Anonymous
    #93288

    Just wondering if the meta value sort ordering is working in the latest build? I’m trying to sort by an ACF date but have not had any luck, in fact have not been able to change the sort order at all no matter what settings I use or if I do it on the back end via sf_edit_query_args. I’ve been able to tweak the filtering in other ways, just not the order…

    Ross Moderator
    #93336

    Hey Scott

    Is it possible you have a pre_get_posts somewhere in your theme, that may be jumping in / hijacking our sort order on the query?

    Have you tried sf_edit_query_args with a different priority so it runs later, like 2000?

    Thanks

    Anonymous
    #93341

    That would not surprise me, it’s a really complex site with a ton of custom stuff going on. I’ll give that a go and let you know if anything changes. Thanks!

    Anonymous
    #93355

    Might have made some progress. When I change the priority I now get no results instead of results in the wrong order. Here’s a code sample:

    function filter_sort_by_start_date( $query_args, $sfid ) {
    
    if( $sfid==2298 ) {
        $query_args = array(
          'meta_key' => 'class_date',
          'orderby' => 'meta_value_num',
          'order' => 'DESC'
        );
    }
    
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_sort_by_start_date', 2000, 2 );

    I’m getting the “no result” result even if I comment out the other ‘pre_get_posts’ calls.

    Anonymous
    #93357

    Got this working. Took another approach and used a pre_get_posts filter to set the order and it seems to be fine now.

    Ross Moderator
    #93482

    Ah great stuff.

    Did you set it with really low priority to go after other pre_get_posts that were possibly conflicting in your setup?

    Anonymous
    #93567

    Yup, that was exactly it. Took a bit of trial and error to get it right but seems to be good now. Thanks for pointing me in the right direction!

    Ross Moderator
    #93572

    Good stuff and good to know 🙂

    Closing this thread

Viewing 8 posts – 1 through 8 (of 8 total)

Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.