Forums › Forums › Search & Filter Pro › Sort order by custom field not working properly
Tagged: Post Types Order
- This topic has 7 replies, 2 voices, and was last updated 5 years, 3 months ago by Anonymous.
-
Anonymous(Private) August 15, 2019 at 2:19 am #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
Trevor(Private) August 16, 2019 at 7:12 am #219094That 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:
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; }
-
AuthorPosts