How can I establish the correct order? I have tried all the available ones but they don't apply. I wish there was a way to add a parameter to the shortcode (or to the view) that allows me to do that...
A View to query posts uses the core WordPress query functions (e.g. get_posts, which utilises the WP_Query class), and Views provides a UI to specify the query arguments. The most common scenarios are provided for in the UI, but some possible settings may be missing, and you can use the Views API hooks to specify them via code.
If you are passing a list of IDs for the posts that should be returned by the query then I expect that means the query uses the 'post__in' argument to list the IDs.
In which case the 'orderby' argument should be 'post__in', so that it uses that same list to order the results.
This request is fairly simple, so let me provide you with an example of the code you would need. Add this as a snippet to Toolset > Settings > Custom Code, the only thing you should need to edit is the View ID you want to apply this to:
function tssupp_filter_query( $view_args, $view_settings, $view_id ) {
// only apply to specific Views
if ( in_array( $view_id, array( 123 ) ) ) { // Edit with View ID(s)
$view_args['orderby'] = 'post__in';
}
return $view_args;
}
add_filter( 'wpv_filter_query', 'tssupp_filter_query', 101, 3 );
The site is likely crashing because you cannot declare the same function twice.
If you want the same to work with different Views you need to pass the View IDs as an array, so modifying my earlier example to include several Views would give
function tssupp_filter_query( $view_args, $view_settings, $view_id ) {
// only apply to specific Views
if ( in_array( $view_id, array( 123, 456, 789 ) ) ) { // Edit with View ID(s)
$view_args['orderby'] = 'post__in';
}
return $view_args;
}
add_filter( 'wpv_filter_query', 'tssupp_filter_query', 101, 3 );
You shouldn't need to test for is_admin etc. if you add your code to Toolset > Settings > Custom Code, where you can specify where the code should run (e.g. front end).