Last active
September 18, 2022 23:16
-
-
Save mishterk/b8a3946bdde62fe4de2b211d0271debc to your computer and use it in GitHub Desktop.
How to show the age of each post in an ACF relationship field. For more info see https://philkurth.com.au/tips/customise-the-post-titles-in-acf-relationship-field/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'acf/fields/relationship/result/name=related_posts', function ( $title, WP_Post $post, $field_arr ) { | |
$posted_at = get_post_time( 'U', false, $post->ID ); | |
$now = current_time( 'timestamp' ); | |
$diff = human_time_diff( $posted_at, $now ); | |
return $title . sprintf( ' (%s ago)', $diff ); | |
}, 10, 3 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I worked out a solution using get_field thank you. The tough part was that a field in the field group was set as a “post object” so I couldn’t use $post->ID for that field type but rather “post-title”