Support

Account

Home Forums General Issues How to order by date field Reply To: How to order by date field

  • This answer marked as private, so this is my contribution:

    
    <?php
    global $wpdb;
    $posts = $wpdb->get_results( '
    	SELECT
    		wp_posts.ID,
    		wp_posts.post_title,
    		wp_posts.post_content
    	FROM wp_posts
    	INNER JOIN wp_postmeta
    		ON wp_posts.ID = wp_postmeta.post_id
    	WHERE
    		wp_postmeta.meta_key = "your_acf_date_var"
    		AND wp_posts.post_type = "your_post_type"
    		AND wp_posts.post_status = "publish"
    	GROUP BY wp_posts.ID
    	ORDER BY wp_postmeta.meta_value ASC
    ' );
    foreach ( $posts as $key => $value ) {
    	var_dump( $value->post_title );
    }
    ?>