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 );
}
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.