Tell us what you are trying to do?
I have a view that is placed on a page via Shortcode like this:
[wpv-view name="View Mitarbeiter Grid by ID" ids="2737,2646,4007,4035,4039,4044,2968"]
I want to order the output by the exact same order I provided in the shortcode.
I also tried some custom code, but couldn't get it working:
add_filter('wpv_filter_query', function($query_args, $view_settings) {
// Check if it's the correct View
if (isset($view_settings['view_id']) && $view_settings['view_id'] == '17219') {
// Get the IDs from the shortcode
if (isset($view_settings['ids']) && !empty($view_settings['ids'])) {
$ids = explode(',', $view_settings['ids']);
$query_args['post__in'] = $ids; // Include only these posts
$query_args['orderby'] = 'post__in'; // Order by the given IDs
}
}
return $query_args;
}, 101, 2);
Hello. Thank you for contacting the Toolset support.
Can you please share problem URL and admin access details and tell me on what section you added your view.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I've added the following view's filter hook to "Custom Code" section offered by Toolset:
=> hidden link
add_filter('wpv_filter_query','func_change_sort_order_as_per_views_shortcode_argument', 101, 3);
function func_change_sort_order_as_per_views_shortcode_argument($query_args, $view_settings,$view_id) {
// Check if it's the correct View
if ($view_id == 17219) {
global $WP_Views;
$shortcode_attribute_ids = $WP_Views->view_shortcode_attributes[0]['ids'];
$ids = explode(',', $shortcode_attribute_ids);
$query_args['post__in'] = $ids; // Include only these posts
$query_args['orderby'] = 'post__in'; // Order by the given IDs
}
return $query_args;
}