Skip Navigation

[Gelöst] sorting by api using wp_query

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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:
=> https://toolset.com/forums/topic/sorting-by-api-using-wp_query/#post-691182

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created vor 6 Jahren, 6 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von mohammadD vor 6 Jahren, 6 Monaten.

Assistiert von: Minesh.

Author
Artikel
#691164

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
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
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?

#691182

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: 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 );

Where:
- Replace 9999 with your original view id.

#691350

tnx