I want to sort posts by a meta value in a custom field. Basically I've added a field called 'date_event' and want to sort the posts by that date (stored as YYYYMMMDD).
The only working example I have is this placed in the loop.php:
$query = new WP_Query( array( 'meta_key' => 'date_event', 'orderby' => 'meta_value_num', 'order' => 'DESC', ) );
This does the trick by sorting, but it takes all posts and sorts them no matter what category I'm viewing. From what I can see it's because I've called the
$query again and not 'filtering' the posts I guess. It might also just be bad coding.
Anyway my goal is to have the posts sorted but only display the posts that are in that category you are in.
Any tips or references are greatly appreciated.