Buenos días.
Tengo una view en la que inserto los elementos a visualizar pasando en la view la ID de estos. [wpv-view name="Filter by post id" ids="302,12,309"]
Existe la opción de ordenar estos resultados por el orden marcado en el parámetro de la view "ID" esto es [wpv-view name="Filter by post id" ids="post1, post2, post3, post4, ..."]. Querría especificar yo mismo el orden y que no sea ni ascendente ni descendente.
¿Es esto posible?
Gracias.
Hello,
This is English support forum, I can answer this ticket in English, hope it is not a problem.
There isn't such kind of built-in feature within Views plugin, but it is possible with some custom codes, for example, you can put below PHP codes into your theme file "functions.php":
add_filter( 'wpv_filter_query', function($query_args, $view_settings, $view_id){
if($view_id == 123){
$query_args['orderby'] = 'post__in';
}
return $query_args;
}, 99, 3);
Please replace 123 with the ID of your view "Filter by post id".
More help:
https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
Hello,
it doesn´t work. And i tried doing a changes in orderby parameter too and is not working. For example order by rand and doesn´t do nothing.
add_filter( 'wpv_filter_query', function($query_args, $view_settings, $view_id){
if($view_id == 4638){
$query_args['orderby'] = 'rand';
}
return $query_args;
}, 99, 3);
thanks.
I have tested above codes in my localhost in a fresh wordpress installation + the latest version of Toolset plugins, it works fine.
Please check these in your website:
1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/
2) You can also provide a test site with the same problem, also point out the problem page URL, I can setup a demo for you.
Hi,
I have the latest versions. one more question.
In the view in the order option, which option should I choose? or is it indifirent,
because I pass it through the filter?
The insert code of the view is this, not? {!{wpv-view name='gladys-galeria' ids="6423,6605,6764,6604"}!}
Above custom PHP codes will override view's order option, in my localhost, I use option: order by post date.
I have enabled the private message box again, in case you still need assistance for it.
I have done below modifications in your website,
1) edit your theme file "functions.php", replace line 34 from:
To:
2) In order to test the result, edit the post view "GLADYS GALERIA", display the post ID just after post title:
<span>[wpv-post-title] (post id: [wpv-post-id])</span>
3) Test it in front-end:
enlace oculto
I can see the result is in right order:
7099,5531,5529,5579,5580,5595,5602,5541,5534,5535,5519
Please check if it is what you want, you can remove the post ID shortcode of step 2), thanks
My issue is resolved now. Thank you!