Skip Navigation

[Resolved] Order the parametric search by a custom field

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here was that the user wanted to know if it was possible to order the search results of a parametric search

Solution:

We actually have some documentation on how to do this.
https://toolset.com/documentation/user-guides/allowing-visitors-to-sort-the-front-end-results/

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by matthewL-6 6 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#607089

Tell us what you are trying to do?
I have a hierarchy in my view, the posts are ordered by a custom field. I have used letters as apposed to numbers.
A, B,C,D ETC... In descending order

Is there any documentation that you are following?
I have found this code and tried to modify it but with no luck

/***---My Code ---***/

add_filter( 'wpv_filter_query', 'hook_search_custom_fields', 10, 2 );
function hook_search_custom_fields( $query_args, $view_settings ) {

if($view_settings['view_id'] == 9379) {
$query_args['orderby'] = array( 'meta_value_string');
$query_args['meta_key'] = 'wpcf-listing-type';
$query_args['meta_type'] = 'string'; //

}
return $query_args;
}

/***---My Code End ---***/

Is there a similar example that we can see?

Here is the post where I got the code and the original code from the post

/***---Link---***/

https://toolset.com/forums/topic/orderby-custom-field-not-working-in-views-parametric-search/#post-375744

/***---Code ---***/

add_filter( 'wpv_filter_query', 'hook_search_custom_fields', 10, 2 );
function hook_search_custom_fields( $query_args, $view_settings ) {

if($view_settings['view_id'] == 111) {
$query_args['orderby'] = array( 'meta_value_num');
$query_args['meta_key'] = 'cf-job-growth-pct';
$query_args['meta_type'] = 'numeric'; //

}
return $query_args;
}
/***---Code End ---***/
What is the link to your site?

hidden link

#607193

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screen Shot 2018-01-17 at 9.37.58 AM.png

Hi Matthew,

Thank you for contacting our support forum.

There is actually an order section in your view that you can use to order your results without the use of any code.

Take a look at the screenshot i've posted.

Thanks,
Shane

#607367

Turned out some of the posts had the wrong data in the field which was being used to order the archive and that is why the search results were off thanks for the help.