Hello all,
I have a custom post type for staff members and at the bottom of each page I have a section where the page editor can add a list of staff members using a repeater field with a post object field nested underneath it. This all works well.
My issue is with the post object field not being searchable. I would like people to be able to use the search to locate the staff members listed on the page. My idea to get around this was to create a hidden field (called searchables) that would be dynamically populated by the contents of the post object field. I just need to grab the name field from each of the post objects and list them in the hidden searchables field.
To do this I was using the acf/update_value filter to go and get the employee names and put them in the searchables field.
//Update Searchables Field
function my_acf_update_value( $value, $post_id, $field ) {
$value = ”;
if( have_rows(’employee_group’) ):
while ( have_rows(’employee_group’) ) :
the_row();
$post_objects = get_sub_field(‘group_members’);
if( $post_objects ):
foreach( $post_objects as $post):
setup_postdata($post);
$name = the_field(’employee_name’). ‘, ‘;
$value .= $name;
endforeach;
wp_reset_postdata();
endif;
endwhile;
else :
endif;
return $value;
}
add_filter(‘acf/update_value/name=searchables’, ‘my_acf_update_value’, 10, 3);
I am a bit lost at the moment trying to get name field to show in the hidden field. Also I need to add some code that keeps the update specific to that row so the repeater field can be used to create more than one employee group on the page if needed.
Any suggestions on how I might do this is greatly appreciated.
Thanks,
Ben