Skip Navigation

[Resolved] How to remove ordering in shortocde?

This support ticket is created 2 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 2 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#2066123

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.

#2066263

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.