Skip Navigation

[Résolu] sorting by api using wp_query

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: How to change sort order using view's API hook

Solution: You can use view's hook 'wpv_filter_query' to change sort order.

You can find proposed solution, in this case, with the following reply: =>

Relevant Documentation:

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.

This topic contains 2 réponses, has 2 voix.

Last updated by mohammadD Il y a 3 années et 3 mois.

Assigned support staff: Minesh.


i need sort results and for some reasons i don't want use views sorting controls

well there is a hook for views i'm using: wpv_filter_query
and i believe i can use ordering methods of wp_query
with the $query_args parameter of the hook;

for example i'm doing this in callback_function:
$query_args["orderby"] = "title";
$query_args["order"] = "ASC";
return $query_args;

but it is not in use;

how can i change the orderby and order of a query using API?



Languages: Anglais (English )

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

Hello. Thank you for contacting the Toolset support.

Well - could you please try to use following code and try to resolve your issue. The key thing here is that we need to set high priority for this hook.

function custom_ordering( $view_args, $view_settings, $view_id ) {
    if ( $view_id == 9999) { // edit the id
         $view_args['orderby'] = 'title';
        $view_args['order'] = 'ASC';
    return $view_args;
add_filter( 'wpv_filter_query', 'custom_ordering', 101, 3 );

- Replace 9999 with your original view id.