Home › Forums › Backend Issues (wp-admin) › How can I add the post date to Post Object select and display? › Reply To: How can I add the post date to Post Object select and display?
Thanks, actually, I figured it out; I had to use $post->ID, as $post_id gave me the same date for all posts.
And I used a different concatenation method to put the date first:
function add_post_object_date( $title, $post, $field, $post_id ) {
$post_date = get_the_date( 'j F Y - ',$post->ID);
$date_title = "$post_date $title";
return $date_title;
}
add_filter('acf/fields/post_object/result', 'add_post_object_date', 10, 4);
And FYI for anyone else reading, this sorts the post objects by date in the backend:
add_filter( 'acf/fields/post_object/query', 'change_posts_order' );
function change_posts_order( $args ) {
$args['orderby'] = 'date';
$args['order'] = 'DESC';
return $args;
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.