Home Forums General Issues Filtering Label for Post Object Field


Filtering Label for Post Object Field

  • Hi there:

    Without going into too much detail I used the front end forms feature with ACF to set up forms on some of the archive templates in my theme which allow users to filter the archive by various form values.

    On one of the filter forms I am using a post object field which displays posts from a custom post type called people (the people post type is basically a staff directory). In this case the post object field lets research projects be filtered by the person working on them. Due to redirects from a past website the post names for all people use the last name followed by the first name. When displayed in the post object field the field appears to display the post title as the label in the drop down, which in this case is listing people last name followed by first name.

    What I would like to do is to have the names displayed by first name followed by last name in the labels for the post object field. Is it possible to do this through one of the field filters for a post object (load_field etc)?

    One last note: the first and last names within the people post type are saved as ACF fields, in case that is relevant in allowing the labels to be sorted.

    Hope all of the above makes sense! Please get back to me when you have a chance. Thanks!


    add_filter('acf/fields/post_object/result/name=post_object_field_name', 'my_post_object_result', 20, 4);
    function my_post_object_result($title, $post, $field, $post_id) {
      $title = get_field('first_name_field', $post_id).' '.get_field('last_name_field', $post_id);
      return $title;
  • Hi John:

    Thanks for getting back to me. The solution you provided above is exactly what I was looking for. I went through the filters documentation before posting here, sorry I missed this!

    Thanks again for your help, I really appreciate the excellent support you provide here.

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

The topic ‘Filtering Label for Post Object Field’ is closed to new replies.