Support

Account

Home Forums Backend Issues (wp-admin) Replacing custom post type post title with an acf?

Solved

Replacing custom post type post title with an acf?

  • Hello,

    I am trying to autogenerate the title and slug out of two custom fields within a custom post type.
    The custom post type is: kuenstler
    Custom field one: vorname-kuenstler
    Custom field two: nachname-kuenstler

    Title should be “vorname-kuenstler [space]nachname-kuenstler” and slug should be “vorname-kuenstler-nachname-kuenstler”

    I have tried to follow the instruction within this thread, but I somehow cannot get it to work. I am using the latest release of ACF.

    Has somebody a working solution, which she/he could share. That would be really great!!!

  • Hello,

    I am trying to autogenerate the title and slug out of two custom fields within a custom post type.
    The custom post type is: kuenstler
    Custom field one: vorname-kuenstler
    Custom field two: nachname-kuenstler

    Title should be “vorname-kuenstler [space]nachname-kuenstler” and slug should be “vorname-kuenstler-nachname-kuenstler”

    I have tried to follow the instruction within this thread, but I somehow cannot get it to work. I am using the latest release of ACF.

    Has somebody a working solution, which she/he could share. That would be really great!!!

  • Hello!

    I am trying to autogenerate the title and slug out of two custom fields within a custom post type.
    The custom post type is: kuenstler
    Custom field one: vorname-kuenstler
    Custom field two: nachname-kuenstler

    Title should be “vorname-kuenstler [space]nachname-kuenstler” and slug should be “vorname-kuenstler-nachname-kuenstler”

    I have tried to follow the instruction within this thread, but I somehow cannot get it to work. I am using the latest release of ACF.

    Has somebody a working solution, which she/he could share. That would be really great!!!

  • Hello,
    I have tried the other recommendations but sadly failed to achieve the following.

    I have the custom post type: “kuenstler” and the custom fields “vorname-kuenstler” and “nachname-kuenstler”.
    I now try to achieve the auto-creation of the post title and slug from these two custom fields.
    Title: “”vorname-kuenstler”[space]”nachname-kuenstler””
    Slug: “vorname-kuenstler”-“nachname-kuenstler”

    Could anybody give me a helping hand here?
    That would be so great!
    Thank you!!!

  • I have got it to work with the following code:

    `

    //Custom Title&Slug Künstler von ACF fields
    function kuenstlerinnen_title_updater( $post_id ) {

    $my_post = array();
    $my_post[‘ID’] = $post_id;
    $my_post[‘post_name’] = $post_name;

    $kvorname = get_field(‘_kuenstlerinnen_vorname’);
    $knachname = get_field(‘_kuenstlerinnen_ nachname’);
    $vname = $kvorname .’ ‘. $knachname;

    if ( get_post_type() == ‘kuenstlerinnen’ ) {
    $my_post[‘post_title’] = $vname;
    $my_post[‘post_name’] = sanitize_title( $title );

    }

    // Update the post into the database
    wp_update_post( $my_post );

    }
    // run after ACF saves the $_POST[‘fields’] data
    add_action(‘acf/save_post’, ‘kuenstlerinnen_title_updater’, 20);

Viewing 5 posts - 26 through 30 (of 30 total)

The topic ‘Replacing custom post type post title with an acf?’ is closed to new replies.