Home Forums Backend Issues (wp-admin) Append/prepend to related fields


Append/prepend to related fields

  • Hoping someone can help with understanding how to dynamically append/prepend info from one related field to another in the admin area form.

    I have three custom field groups set up – one for Artists (name), one for Artist Projects (title,images,artist), and finally an Album (name,artist_projects).

    I create two Artists, and then I create six Artist Projects and relate them to their respective Artist with a relationship field. All good there.

    An Album consists of Artist Projects from multiple Artists. My Album group contains:
    Title, Description, Artist Project(s)

    The issue I’m facing is that when we reach several hundred Artist Projects, finding the right Artist Projects to attach may be tricky. Is there a way to prepend/append an Artist name to the Artist Project titles as they are listed in the relationship field interface? The admin user could then search for the Artist name and find the Artist Projects they are looking for. For example “Artist Project 1” by Joe Bloggs would display as “Joe Bloggs – Artist Project 1” on the Album form page in wp-admin.

    I’m thinking this filter is likely useful, but I’m struggling to find examples of this code being used to get related values and return a new title etc.

    Hoping someone might be able to point me in the right direction 🙂


  • I’ve made progress with this with the following code:

    add_filter('acf/fields/relationship/result/key=field_63b7f8c607ba7', 'my_acf_fields_relationship_result', 10, 4);
    function my_acf_fields_relationship_result( $text, $post, $field, $post_id ) {
    	$project_artist = get_field('artist',$post->ID);
    	return $text." (".$project_artist[0]->post_title.")";

    …my issue now is that the wp-admin search for the relationship field doesn’t see the appended artist names. Is there some way for the search to see this?

  • I’m not sure what “appended artist names” means. Where is this field? on the posts returned by get_field('artist',$post->ID);? If this is the case then you need to get the values from that post.

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

You must be logged in to reply to this topic.