Amazing, thanks. I added in a little extra code as I’m using a unique ID for the questions (in case they change the question text):
$question = get_post_meta($post_id, $repeater.'_'.$i.'_'.$subfield, true); $uid = get_post_meta($post_id, $repeater.'_'.$i.'_'.'uid', true); $this->choices[$uid] = $question;
Thanks again! Really appreciate you taking the time to look at this.
I created a separate field “dependency2” that wasn’t within the repeater and it seems to work fine. Something in the repeater side of things must be causing the issue. I guess it doesn’t like me calling to the parent field from a sub-field filter (since “dependency” is a sub-field of “questions”).
Maybe I’ll just have to store the dependencies as a separate set of fields…
Thanks for all your help on this by the way! 🙂
echo '<pre>'; print_r($field); echo '</pre>'; seems to run a bunch of times, out putting the same array, maybe 50+ times, but nothing from
echo '<pre>'; print_r(get_field('questions', $post->ID); echo '</pre>';.
It then doesn’t render anything after (so none of the other sub-fields). This is the array it’s spitting out for $field:
Array ( [ID] => 15 [key] => field_56f0735c7223d [label] => Dependency [name] => dependency [type] => select [value] => [required] => 0 [id] => [class] => [conditional_logic] => 0 [parent] => 6 )
It seems like it’s the get_field() function that stops anything further from running.
Yes, so once the user has saved a questionnaire they’re then able to edit the list of questions to add dependencies between questions.
if(!isset($_GET['post'])) return array(); so that the code wouldn’t try running if the post didn’t have an ID (ie. when it’s a new post – since then there wouldn’t be any custom fields to find, since the post would have never been saved).
Also, to elaborate on what happens, as soon the edit page gets to the repeater field containing the select the code breaks and no more PHP appears to be processed. There are no errors in the log, however.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!