Skip Navigation

[Resolved] How to list articles in same order as passed ids in the shortcode

This support ticket is created 2 years, 4 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by nevilP 2 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#2412171

I’m listing up articles (pages) by inserting this shortcode:
[wpv-view name="menu-articles" ids="4799, 4793, 4801, 11824, 7344, 4455, 792, 830, 4643, 4658”]

How do I list the articles in the same order as the ids in the shortcode?
Thanks in advance 🙂

#2412207

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

To order the view result based on the shortcode attribute "ids" values, you will have to add the view's filter hook "wpv_filter_query":

You should try to add the following code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

add_filter( 'wpv_filter_query', 'func_orderby_shortcode_attribute_values', 101, 3 );
function func_orderby_shortcode_attribute_values($query, $setting, $views_ID) {
    if($views_ID == 99999) {
        
      		$query['orderby'] = 'post__in';
      		      	 
    }
    return $query;
}

Where:
Replace 99999 with your original view ID.

More Info:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#2412247

Problem solved – thanks 🙂