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!

Related Questions

WordPress Importer “Failed to import Media”

0  Asked on January 19, 2021 by orbita


Override theme file from plugin

0  Asked on January 18, 2021 by toma-tomov


Why can I not view image attachment pages?

3  Asked on January 17, 2021 by h-hall


Image color changes in wordpress

0  Asked on January 16, 2021 by giulia


Inserting additional   into menu item text

2  Asked on January 16, 2021 by marsandback


wp_mail() not sending emails with ajax

2  Asked on January 16, 2021 by mohd-hasan


How to ignore fields if empty?

1  Asked on January 16, 2021 by israel-santiago


Change WordPress post-state in Admin Area

2  Asked on January 16, 2021 by gino


Select posts with any post_type from database?

1  Asked on January 15, 2021 by lisandro-vaccaro


Why does WP_Post not contain its permalink?

3  Asked on January 14, 2021 by dodov


How to check post type when using sanitize_title hook?

1  Asked on January 14, 2021 by michael-rogers


WordPress retrieve media except cropped

0  Asked on January 12, 2021 by adviner


You have an error in your SQL syntax – Help with query

2  Asked on January 11, 2021 by ogmios


Is it possible to display tag cloud widget by category?

1  Asked on January 11, 2021 by taller-de-wordpress


Ask a Question

Get help from others!

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