Support Forums

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Sort order by custom field not working properly

Viewing 8 posts - 1 through 8 (of 8 total)
  • Gareth Lockett
    #219023

    Hi,

    I have Search and Filter working on a custom post archive page. I have a sort field which sorts by a Meta Value which corresponds to a numeric ACF custom field.

    When you choose to sort by ascending or descending order with these fields, the order of the results changes but not in the order you’d expect (numerically).

    Could you take a look please?

    Thanks

    Gareth Lockett
    #219024
    This reply has been marked as private.
    Trevor Moderator
    #219034
    This reply has been marked as private.
    Gareth Lockett
    #219058
    This reply has been marked as private.
    Trevor Moderator
    #219067

    Could you deactivate the Post Types Order plugin and check?

    Gareth Lockett
    #219088

    Okay, yeah that fixes it. So is there any way to make that plugin work with S&F sorting?

    Trevor Moderator
    #219094

    That plugin, and others like it, will impact sorting in our plugin as it acts later in the WordPress page creation process. Post Types Order does have a hook you can use though, to stop it working under conditions that you set. It is discussed here:

    https://wordpress.org/support/topic/to-avoid-plugin-conflict-how-to-disable-post-type-order-for-search-pages/

    Maybe like this (in your child theme functions.php file):

    add_filter('pto/posts_orderby/ignore', 'pto_ignore', 10, 3);
    function pto_ignore( $ignore, $orderBy, $query ) {
      global $searchandfilter;
    $sf_current_query = $searchandfilter->get(12345)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
    } else {
      $ignore = TRUE;
    }
    return $ignore; 
    }

    Where 12345 is changed to the ID of your search?

    I am not sure if this is much the same, but simpler/shorter:

    add_filter('pto/posts_orderby/ignore', 'pto_ignore', 10, 3);
    function pto_ignore( $ignore, $orderBy, $query ) {
      global $searchandfilter;
    $sf_current_query = $searchandfilter->get(12345)->current_query();
    if (!((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==""))) $ignore = TRUE;
    return $ignore; 
    }
    Gareth Lockett
    #219099

    Okay, brilliant. Will give it a go.

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

You must be logged in to reply to this topic.