Home › Forums › Backend Issues (wp-admin) › Show Ninja Form if True/False?
Hey there,
Is there a way to work with a Ninja Forms query to only display form submissions if a true/false ACF option is checked with the submission?
I currently have created the ACF true/false field and see it on each of the form submissions, but I don’t know how to setup an if statement to conditionally show them. It could be that maybe Ninja Forms and ACF don’t work well together? Here’s what I have so far:
$args = array(
'6' => $form_id,
'fields' => array(
),
);
$subs = Ninja_Forms()->subs()->get( $args );
foreach ( $subs as $sub ) {
$form_id = $sub->form_id;
// Returns an array of [field_id] => [user_value] pairs
$all_fields = $sub->get_all_fields();
// Echoes out the submitted value for a field
echo '<li><div class="testimonial"><span class="testimonial-stars">' . $sub->get_field( 9 ) . '</span> stars<br>' . $sub->get_field ( 10 );
echo '<div class="reviewer">-' . $sub->get_field( 7 ) . ', ' . $sub->get_field( 8 ) . '</div></div></li>';
If I have a true/false field that is called ‘use_on_listing_page’ for example, is there a way to integrate an if statement in the ninja forms query with ACF?
I’m not sure I completely understand.
Is the true/false field displayed on the ninja forms post type for each submission?
If that is the case I’m not sure I can tell what value in your code represents the post_id of each submission. Is it $form_id?
If you have this attached to the form post type and $form_id represents the post ID then maybe something like the below.
Keep in mind that this is only a quess, this is really an ninja forms question.
<?php
$args = array(
'6' => $form_id,
'fields' => array(),
);
$subs = Ninja_Forms()->subs()->get( $args );
foreach ($subs as $sub) {
$form_id = $sub->form_id;
if (get_field('name_of_true_false_field', $form_id)) {
// Returns an array of [field_id] => [user_value] pairs
$all_fields = $sub->get_all_fields();
// Echoes out the submitted value for a field
echo '<li><div class="testimonial"><span class="testimonial-stars">'.
$sub->get_field(9).'</span> stars<br>'.$sub->get_field (10);
echo '<div class="reviewer">-'.$sub->get_field( 7 ).
', ' . $sub->get_field( 8 ) . '</div></div></li>';
}
}
?>
If that’s not right, please supply more information.
The topic ‘Show Ninja Form if True/False?’ is closed to new replies.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.