Add repeater field data to only selected post

WordPress Development Asked by Waleedviews on September 26, 2020

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.

$query = new WP_Query( array(
        'post_type' => array('artist', 'musicbrainz'),
        'posts_per_page' => $posts,
        'order' => 'DESC',
        'meta_query' => array(
            'key' => 'feature_on_site',
            'value' => 'yes',
            'compare' => 'LIKE',
    ) );

    if ( $query->have_posts() ):?>
            <?php while ( $query->have_posts() ) : $query->the_post(); ?>
            //from code
       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 =
                                "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>
                        <?php }
                             <form name="command" id="review_product_form" class="user_input_form review_product front-reviews" action=""
                            <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>

        <?php endwhile; ?>
        <?php endif; ?>

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

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP