1

I want to add an ACF field in my post title, only on admin table (not in the title field stored in database), and only for a specific Custom Post Type. Some of my posts have the same name, so it will be more useful to have this information. In final, my title will look like that :

$new_title = get_the_title($post->ID).' - '.get_field('place', $post->ID);

I have found other solutions on other topics, but all the post types are affected. Thank you.

1 Answer 1

1

Use this to filter the title:

add_action(
    'admin_head-edit.php',
    'wpse264139_edit_post_change_title_in_list'
);
function wpse264139_edit_post_change_title_in_list() {
    add_filter(
        'the_title',
        'wpse264139_construct_new_title',
        100,
        2
    );
}`

`function wpse264139_construct_new_title( $title, $id ) {
    if(get_post_type($id) == 'post_type') {
       $field = get_field('place', $id);
       return $field . " " . $title;
    }
    else {
       return $title;
    }
}

NOTE: most of the code came from: Replacing the title in admin list table

2
  • Yes but how to hook for replacing the title in admin table List (for this post type only)? Commented Apr 19, 2017 at 15:09
  • Edited answer with get_post_type()
    – Samyer
    Commented Apr 20, 2017 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.