Support

Account

Home Forums Front-end Issues pre_get_posts query to sort after date_picker

Unread

pre_get_posts query to sort after date_picker

  • Hi, i would like to sort all posts according to the date of my start_time meta field. But no matter what i try i always get Nothing Found. Also had no luck when i try get_posts or a WP_Query.

    What am i doing wrong?

    Here’s the code:

    function mind_pre_get_posts( $query ) {
      
      if( is_admin() ) {
        return $query; 
      }
      if( $query->is_main_query() ) {
        
        $query->set('orderby', 'meta_value'); 
        $query->set('meta_key', 'start_time');   
        $query->set('order', 'DESC'); 
        
      }
      return $query;
    }
    add_action('pre_get_posts', 'mind_pre_get_posts');

    And here’s the custom field group:

    
    	acf_add_local_field_group(array(
    		'key' => 'group_1',
    		'title' => 'Meta info',
    		'fields' => array (
               		 array (
    				'key' => 'start_time',
    				'label' => 'Exhibition start',
    				'name' => 'exhibition_start',
    				'type' => 'date_picker',
    			),
              		  array (
    				'key' => 'end_time',
    				'label' => 'Exhibition end',
    				'name' => 'exhibition_end',
    				'type' => 'date_picker',
    			)
    		),
    		'location' => array (
    			array (
    				array (
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'post',
    				),
    			),
    		),
    	));
    
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.