Add repeater field data to only selected post

Question

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.

0
, , , Waleedviews 5 months 0 Answers 54 views 0

Leave an answer