Support

Account

Home Forums Backend Issues (wp-admin) Get Relation Field on Post Title

Helping

Get Relation Field on Post Title

  • Hi, i have this code

    /** Create Title and Slug */
    function acf_title( $value, $post_id, $field ) {
     if ( get_post_type( $post_id ) === 'predicciones-nba' ) {
     
     $new_title = get_field( 'fecha_partido', $post_id ) . ' ' . $value;
     $new_slug = sanitize_title( $new_title );
    
     wp_update_post(
     array(
     'ID' => $post_id,
     'post_title' => $new_title,
     'post_name' => $new_slug,
     )
     );
     }
     return $value;
    }
    add_filter( 'acf/update_value/name=pronostico', 'acf_title', 10, 3 );

    So its works.
    The issue is that I want to add to the title also a relationship field that I have called “teams” its return a post objects list, which selects from another CPT the teams that face each other, so for example I can select from that CPT “Team A” and “Team B”, finally my idea is that the title is autocompleted with the date + team a + ‘vs’ + team b

  • The first thing is that when you want to update the title of a post based on ACF fields you need to use the acf/save_post hook. The reason is that all of the other fields may not be saved/updated when a specific field’s acf/update_value hook is fired.

    For the rest you should look at the documentation for using a relationship field.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.