Show Post Type and Date in ACF Relationship Results
Adds the post type and publish date after each title in ACF relationship and post object fields, so similar titles are easy to tell apart.
Opens WPIDE on
Code
$wpide_acf_result_details = function ( $text, $post ) {
if ( ! $post instanceof WP_Post ) {
return $text;
}
$type = get_post_type_object( $post->post_type );
return $text . ' (' . esc_html( ( $type ? $type->labels->singular_name : $post->post_type ) . ', ' . get_the_date( 'M j, Y', $post ) ) . ')';
};
add_filter( 'acf/fields/relationship/result', $wpide_acf_result_details, 10, 2 );
add_filter( 'acf/fields/post_object/result', $wpide_acf_result_details, 10, 2 );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.