Skip Navigation

[Resolved] Ordenar una view por ID

This support ticket is created 4 years, 8 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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/Hong_Kong (GMT+08:00)

This topic contains 7 replies, has 2 voices.

Last updated by urkoP 4 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1316101

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.

#1316207

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

#1316321

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.

#1316753

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.

#1319173

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"}!}

#1319771

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.

#1319893

I have done below modifications in your website,
1) edit your theme file "functions.php", replace line 34 from:

    if($view_id == 123){

To:

    if($view_id == 4638){

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:
hidden link

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

#1319933

My issue is resolved now. Thank you!

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