Forums › Forums › Search & Filter Pro › sort_order= custom field is not working
Tagged: sort order custom fields
- This topic has 8 replies, 2 voices, and was last updated 7 years, 7 months ago by
Anonymous.
-
Anonymous(Private) July 14, 2017 at 10:14 pm #120693
Hi,
I’m trying to add buttons where the user can order by Date, Price and another custom field.
On this resultspage:
http://wbr.ikon.be/te-huur/?_sfm_prijs=0+10000&_sfm_slaapkamers=0+5So if I want to allow the user to sort the results by price (a custom field called ‘prijs’ in my case),
I would add to the url this:
http://wbr.ikon.be/te-huur/?_sfm_prijs=0+10000&_sfm_slaapkamers=0+5&sort_order=_sfm_prijs+desc+num
But this gives 0 results.The same goes for any other custom field I try (num or alpha).
I also tried using the ‘Sort Order’ field in the Search Filter UI and selecte sort by ‘Meta Value’ and then setting ‘prijs’ as the key, but the result is the same as here:
http://wbr.ikon.be/te-huur/?_sfm_prijs=0+10000&_sfm_slaapkamers=0+5&sort_order=_sfm_prijs+desc+numSo these are custom post types with custom fields (ACF PRO)
(The default sorting does work; by ID and date etc).
Thanks in advance
Trevor(Private) July 14, 2017 at 10:36 pm #120700And yet this gives results:
http://wbr.ikon.be/te-huur/?_sfm_prijs=0+10000&_sfm_slaapkamers=0+5&sort_order=_sfm_prijs+num+desc
But not sorted. Is there something wrong with the data in one or more posts for that field?
Anonymous(Private) July 15, 2017 at 11:39 am #120730So none of the custom fields are ‘sortable’. Like ‘slaapkamers’ (bedrooms) for example:
http://wbr.ikon.be/te-huur/?sort_order=_sfm_slaapkamers+num+ascThis is the WP query where the search filter arguments are added to:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'order'=> 'ASC', 'orderby' => 'date', 'post_type' => 'panden', 'posts_per_page' => 9, 'meta_key' => 'status', 'meta_value' => array('Te huur', 'Te huur onder reservatie'), 'paged' => $paged); $args['search_filter_id'] = 71; $pandenLoop = new WP_Query($args);
Trevor(Private) July 15, 2017 at 11:43 am #120732The better way to test if it is sorting properly is to make a test search and test page and use the shortcode results method. No special queries and less potential conflict with other things. The results will look not so good (visually) maybe but it is a reliable base to test from.
Anonymous(Private) July 15, 2017 at 12:43 pm #120742Using shortcodes it does work.
http://wbr.ikon.be/test-results/?sort_order=_sfm_prijs+desc+numDoesn’t work when i use ‘custom’ or ‘archive’ for the results page.
I guess it means I have to customize the /templates/results.php file in the plugin.
Can I override this in my theme maybe?Trevor(Private) July 15, 2017 at 12:48 pm #120744So, if the shortcode method works, and plugins do not change, it is the theme, or the template file.
You can considerably customize the results.php file. The documentation tells you how to copy the file from our plugin template folder, then you can edit it. I have placed examples of different ones in many threads here.
-
AuthorPosts