Support

Account

Home Forums Add-ons Repeater Field Add repeater field data to only selected post

Solving

Add repeater field data to only selected post

  • I have a wp_query with the while loop, I added a form for each post when I submit the form data it submits to other posts as well instead of submitting to the current selected post.

    <?php
    $query = new WP_Query( array(
            'post_type' => array('artist', 'musicbrainz'),
            'posts_per_page' => $posts,
            'order' => 'DESC',
            'meta_query' => array(
            array(
                'key' => 'feature_on_site',
                'value' => 'yes',
                'compare' => 'LIKE',
            )),
        ) );
    
        if ( $query->have_posts() ):?>
                <?php while ( $query->have_posts() ) : $query->the_post(); ?>
                //from code
           <?php
           if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    
                                 $star_ratingg = $_POST['star_ratingg'];
                                 $set_comments = $_POST['set_comments'];
    
                                 
    
                                 if (!empty($current_user) && !empty($star_ratingg)) {
                                 $field_key = "field_5ee00c7122b0c";
                                 $value =
                                array(
                                    "field_5ee00cd522b10"   => $star_ratingg,
                                    "field_5ee00ce322b11"   => $set_comments,
                                );
                                $p_id = get_the_ID();
                            add_row( $field_key, $value, $p_id );
                            //wp_mail($current_user, $subject, $message );
                                } else { ?>
                            <div class="error-access">
                                <p>Please fill your review form.</p>
                            </div>
                            <?php }
                            }
                                 ?>
                                 <form name="command" id="review_product_form" class="user_input_form review_product front-reviews" action=""
                                method="post">
                                <input type="text" name="star_ratingg">
                                <input type="text" name="set_comments">
                                <div class="btn_wrap">
                                                            <div class="btn_text"><input
                                                                    class="form_btn submit_btn btn-seatgeek btn-purchase"
                                                                    type="submit" name="post-review" value="Submit"><input
                                                                    type="hidden" name="get_performer" id="get_performer"
                                                                    value="<?php echo get_the_title(); ?>"></div>
                                                        </div>
                            </form>
    
            <?php endwhile; ?>
            <?php endif; ?>

    When the form is submitted it post the data to other posts of CPT as well.

  • You need to somehow target the field to the post ID of the post being edited and then only update that post.

    maybe something like this (only a quick example)

    
    if (!empty($_POST['star_ratingg'][$post->ID])) {
      $star_ratingg = $_POST['star_ratingg'][$post->ID];
      $set_comments = $_POST['set_comments'][$post->ID];
      // remainder of your update code here
    }
    
    
    <input type="text" name="star_ratingg [<?php echo $post->ID]">
    <input type="text" name="set_comments[<?php echo $post->ID]">
    
  • thankyou for your help, I just test and it doesn’t work,it’s not submitting any data to the ACF fields, any help, please?

  • I’m not sure that I can. The issue is that you have multiplier forms. The fields in each form need to be unique to each post and you need to test for this uniqueness to update the post that the form belongs to.

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

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.