[Resolved] wpv_filter_query custom ordering being overwritten
This support ticket is created 7 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.
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.
Also in wpv_filter_query_post_process debug info says views.
What can i do to change the order of the query? In every view there is a drop down for selecting the order and this seems to be the only thing that lets me change order.
I'm guessing from your question that the post-views-counter adds post meta with a key post_views to the posts to track the views, and that is what you want to search by.
Firstly, you'll need to read up the correct way to use post meta data with orderby. The WordPress codex describes it here: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters, where you will see that you need to add a meta_key value as well as the orderby parameter. If the codex itself is not clear it is easy to find examples online.
Then when you use wpv_filter_query you need to specify a priority, and it is recommended that you add a high priority of, say, 101, so that your function runs after any others. If you leave it with the default priority of 10 other hooks may run after yours.
Note that you are also not running any checks to see what view you are on, so this will affect all views (if you have more than one on your site).
You probably want to set your code up something like this:
add_filter( 'wpv_filter_query', 'most_viewed_video_args', 101, 3 );
function most_viewed_video_args( $query_args, $view_settings, $view_id ) {
if ( $view_id == 27 ) { // edit the id
// your code here
}
return $query_args;
}
No. Forget the fact I mentioned a plugin entirely to simplify this.
I am unable to effect order by using the wpv_filter_query filter. Toolset always makes the query based on the order selected on the view template. Lets say I set it to "Rand" via filter but in the view its set to "date" then it will make the query ordered by date. How can I set this via the filter without it being overridden?