I am trying to dynamically select posts in an ACF relationship field.
This code block creates an array of post IDs to display in the relationship field:
function npep_students_to_show_have_rows_two() {
$student_newest = '';
if (have_rows('npep_student_matches', $post>ID)) {
while(have_rows('npep_student_matches', $post>ID)) {
the_row();
$student_newest[] = get_sub_field('npep_student');
}
}
return $student_newest;
}
$newest = npep_students_to_show_have_rows_two();
I am able to use $newest in a standard WP_Query perfectly. Such as
$the_query = new WP_Query( array('post_type' => 'student', 'posts_per_page' => -1, 'post__in' => $newest ));
However, when I try to use this in the ACF filter function it does not work. I know the filter works because when I set the array manually it works as expected.
add_filter('acf/fields/relationship/query/name=npep_interviewees', 'npep_limit_students', 10, 3);
function npep_limit_students( $args, $field, $post_id ) {
$newest = npep_students_to_show_have_rows_two();
$args['post__in'] = $newest;
// $args['post__in'] = array(71,127,130);
return $args;
}
I am confused 🙁