Tell us what you are trying to do?
The View I am working with has default ordering to a custom field AND the results are taken from the Query Filter by taking the post IDs. Something like this: [wpv-view name="career-category-include-id" include="461321, 461358, 461357, 461515, 461320"]
However, in some cases, I don't want it to sort by that custom field.
I have two questions:
1. How can I remove the sort?
2. If possible, how can I get it to output the results based on which post IDs come first? Taking the example above, post 461321 should come first, then 461358, then 461357, etc.
Hi Stanley,
Thank you for contacting us and I'd be happy to assist.
1. You can use the 'orderby' attribute in the view's shortcode, to override the order by settings in the view:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-view
[wpv-view name="view-name" orderby="title"]
2. To change the view's order to match the order of the IDs passed through the view's shortcode attribute, you'll need to change the 'orderby' in the query to 'post__in' using the 'wpv_filter_query' filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters
For example:
add_filter( 'wpv_filter_query', 'wpv_filter_query_func', 1000 , 3 );
function wpv_filter_query_func( $query_args, $view_settings ) {
// process if specific view
if ( !is_admin() && ( isset($view_settings['view_id']) && $view_settings['view_id'] == 12345) ) {
// change order criteria to provided IDs
$query_args['orderby'] = 'post__in';
}
return $query_args;
}
Note: Please replace '12345' with your actual View's ID.
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
regards,
Waqar