Support

Account

Home Forums General Issues Relationship posts url will have current post url Reply To: Relationship posts url will have current post url

  • Trying to achieve the same.
    I have a post type artists => artist lastname & artist first name field
    and Post Type exhibitions.

    There’s a bidirectional relationship field, which connects exhibitions to artists.

    I want to create a Slug/post-name which is …/[first 3 letters of the 1st artist’s last name]-[exhibition name].

    //Generiert bzw. ersetzt Title&Slug der Ausstellungen automatisch von ACF field Ausstellungstitel. Slug von 1.Künstler
    function ausstellungs_title_updater( $post_id ) {
    
    $my_post = array();
    $my_post['ID'] = $post_id;
    $my_post['post_name'] = $post_name;
    
    $ausstellungstitel       = get_field('_ausstellungen_titel');
    $kuenstlerabk1			= get_field ('_ausstellungen_to_kuenstlerinnen_bez');
    
    if ( get_post_type() == 'ausstellungen' ) {
      $my_post['post_title'] = get_field('_ausstellungen_titel');
     $my_post['post_name'] = sanitize_title($kuenstlerabk1 . $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', 'ausstellungs_title_updater', 20);

    I have used this above example to firstly only insert the exhibition title “ausstellungen_title”, which worked perfectly.

    Adding:

    $kuenstlerabk1			= get_field ('_ausstellungen_to_kuenstlerinnen_bez');
    

    gives me now only array as slug name.
    I have to somehow get the “_ausstellungen_to_kuenstlerinnen_bez”, which is the relationship field to output the slug of the first artist attached.

    Any ideas? THANK You!