I am working with wordpress where i have a sort listing. There is a custom field in my post called “value_event” which date format yyyy/mm/dd. Now i want to sort all posts by value_event. with this query_post command:

This is my code in template for custom post taxonomy-event-date.php

   $args = array(
  'post_status'       => 'publish',
  'posts_per_page'    => 6,
  'paged'             => $paged,
  'meta_key'          => 'value_event',
  'orderby'           => 'meta_value_num',
  'order'             => 'ASC'
  $query = new WP_Query( $args );
  if ( $query->have_posts() ) {
  while ( $query->have_posts() ) {
  <?php the_title(); ?>
  wp_reset_query();  // Restore global post data stomped by the_post().


function search_filter($query){
    if ( !is_admin() && $query->is_tax( 'event', 'date' ) ) {
        $query->set('post_status', 'publish');
        $query->set('meta_key', 'value_date');
        $query->set('orderby', 'meta_value_num');
        $query->set('order', 'ASC');

Read more here: Sort custom post with custom field not working


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: