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

Viewing 7 posts - 1 through 7 (of 7 total)
  • Anonymous
    #219024
    This reply has been marked as private.
    Trevor
    #219034
    This reply has been marked as private.
    Anonymous
    #219058
    This reply has been marked as private.
    Trevor
    #219067

    Could you deactivate the Post Types Order plugin and check?

    Anonymous
    #219088

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

    Trevor
    #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; 
    }
    Anonymous
    #219099

    Okay, brilliant. Will give it a go.

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