Skip Navigation

[Resolved] View orderby original order of arguments in shortcode parameter

This support ticket is created 5 years, 6 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
- 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/Karachi (GMT+05:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by coreyP-2 5 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#1120117

I have a view shortcode that displays particular posts based on the shortcode parameter "postid." Unless I'm missing something, there doesn't seem to be any simple way to order the results by the original order of the arguments. For instance, I want the posts in the following example to display in the same order they are entered:

[wpv-view name="directory-card" postid="4605,4797,4655"]

However, I don't see any equivalent option to "original order of arguments." Is there a simple alteration I can make to the $query_args?

#1120499

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Corey,

Thank you for contacting us and I'll be happy to assist.

You can use filter "wpv_filter_query" to set "$query_args['orderby']" to "post__in", which will show posts in the order they're added in the argument.
( ref: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query )

For example, you can add the following code at the bottom of your active theme's "functions.php" file and update the "xyz" with your view's actual ID:


// custom function to filter output of view based on shortcode parameter
add_filter( 'wpv_filter_query', 'filter_posts_order_fn', 1000 , 3 );
function filter_posts_order_fn( $query_args, $view_settings ) {

    if ( !is_admin() && ( isset($view_settings['view_id']) && $view_settings['view_id'] == xyz) ) {

        $query_args['orderby'] = 'post__in';        
    }
    return $query_args;
}

I hope this helps! Please let us know if you need any further assistance.

#1120788

Thanks, Waqar! That works perfectly. I could have sworn I tried to set "post__in" as the "orderby" arg. I must have had something wrong. Thanks again.

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