0

I have two functions that should be updating a custom post types within a loop.

The problem

If the existing post type post title is longer then one word the posts does not update if the function is run with update_post_meta.

Example.

If the post title for the post is called

title

the function works.

if the post title is called

title subtitle

the function does not work

The code

<?php
$weekNumber     =   $_GET["week_id"];
?>
<h2 class="text-center pt-3 pb-3"> You have selected week <strong><?php echo $weekNumber;?></strong> to be edited</h2>
<form action="" id="primaryPostForm" method="POST" enctype="multipart/form-data">
    <div class="table-responsive">
        <table id="example-2" class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th class="align-middle">NAME</th>
                    <th class="align-middle">TEAM SPIRIT</th>
                    <th class="align-middle">ATTITUDE</th>
                    <th class="align-middle">GIVER GAIN</th>
                    <th class="align-middle">ENTIRE TEAM PRESENT</th>
                    <th class="align-middle">INITIATIVE</th>
                    <th class="align-middle">POINTS POWER OF ONE</th>   
                </tr>
            </thead>
            <tbody>
                <?php $query = new WP_Query(array(
                    'posts_per_page'        => -1,
                    'taxonomy'              => 'powergroup-type',
                    'term'                  => 'all',
                    'orderby' =>  'DESC',
                ) ); ?>
                <?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
                <!-- Start Update Script -->
                <?php
                    $current_post   =   $post->ID;
                    $title          =   get_the_title();
                    $s1             =   $title."s1";
                    $s2             =   $title."s2";
                    $s3             =   $title."s3";
                    $s4             =   $title."s4";
                    $s5             =   $title."s5";
                    $s6             =   $title."s6";
                    $s1scrore       =   '_powergroup_score_week_'.$_GET["week_id"].'_1';
                    $s2scrore       =   '_powergroup_score_week_'.$_GET["week_id"].'_2';
                    $s3scrore       =   '_powergroup_score_week_'.$_GET["week_id"].'_3';
                    $s4scrore       =   '_powergroup_score_week_'.$_GET["week_id"].'_4';
                    $s5scrore       =   '_powergroup_score_week_'.$_GET["week_id"].'_5';
                    $s6scrore       =   '_powergroup_score_week_'.$_GET["week_id"].'_6';

                    $post_information = array(
                        'ID'    =>  $current_post,
                    );
                    $pidac = wp_update_post($post_information);
                        if($pidac)
                        {
                            update_post_meta($pidac, $s1scrore, $_POST[$s1]);
                            update_post_meta($pidac, $s2scrore, $_POST[$s2]);
                            update_post_meta($pidac, $s3scrore, $_POST[$s3]);
                            update_post_meta($pidac, $s4scrore, $_POST[$s4]);
                            update_post_meta($pidac, $s5scrore, $_POST[$s5]);
                            update_post_meta($pidac, $s6scrore, $_POST[$s6]);
                        }

                ?>
                <!-- End Update Script -->
                <tr>
                    <td class="align-middle text-center text-center">
                        <?php echo $title; ?><?php echo $current_post; ?>
                    </td>
                    <td class="align-middle text-center text-center">
                        <input type="checkbox" name="<?php echo $s1 ;?>" value="1">
                    </td>
                    <td class="align-middle text-center text-center">
                        <input type="checkbox" name="<?php echo $s2 ;?>" value="2">
                    </td>
                    <td class="align-middle text-center text-center">
                        <input type="checkbox" name="<?php echo $s3 ;?>" value="3">
                    </td>
                    <td class="align-middle text-center text-center">
                        <input type="checkbox" name="<?php echo $s4 ;?>" value="4">
                    </td>
                    <td class="align-middle text-center text-center">
                        <input type="checkbox" name="<?php echo $s5 ;?>" value="4">
                    </td>
                    <td class="align-middle text-center text-center">
                        <input type="checkbox" name="<?php echo $s6 ;?>" value="6">
                    </td>
                </tr>
                <?php endwhile; endif; ?>
            </tbody>
        </table>
        <div class="form-group">
            <?php wp_nonce_field('post_nonce', 'post_nonce_field'); ?>
            <input type="hidden" name="submitted" id="submitted" value="true" />
            <button class="btn btn-lg btn-primary btn-block" type="submit">Update Score for Week <?php echo $weekNumber ;?></button>
        </div>
    </div>
</form>

the $weekNumber get a value for the url

any advice would be appreciated

  • name attribute of the <input /> can't contain white spaces. – Max Yudin Jul 10 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.