Allow users to change the sort order
-
Hi,
I would like to create a frontend filter allowing users to change the order of posts according to custom fields.
Here is an example of code to filter based on a custom field :
function custom_queries($query){ if ( ! is_admin() && is_post_type_archive( 'event' ) && $query->is_main_query() ) { $query->set( 'orderby', 'meta_value_num' ); $query->set( 'order', 'ASC'); $query->set( 'meta_query', array( array( 'key' => 'custom_field', 'compare' => '>=', 'type' => 'numeric', ) ) ); } } add_action( 'pre_get_posts', 'university_adjust_queries' );
But do you know how to add multiple custom fields and create the filter in frontend ?
Thanks in advance
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Allow users to change the sort order’ is closed to new replies.