Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the morefields plugin to create textfields and checkboxes in the dashboard. For a test I have first created a checkbox on 'pages' if it was checked, the frontend showed the text 'TESTCONTENT', if it wasn't it was showing 'GEEN CONTENT'. It worked, so the code I used is working also.

Now I want to show an extra div in a custom-post-type loop containing a 'new' stamp , so I created a checkbox on the projecten (the name of my CPT.)

I gave this the value and field-key: 'newproject'.

Now when I want to check my checkbox, I go to a project and turn the checkbox on, but when I update the project and look again, the checkbox turned itself off. I can't figure it out, I thought maybe it is because I put a loop in a loop but I don't think it had something to do with the checkbox turning off.

This is my code of the whole loop (so, the loop in the loop)

<?php if (have_posts()) : while (have_posts()) : the_post(); //opening 1st loop?>
                <div class="extracontent-block">
                    <div class="extracontent-block-image">
                        <?php $newproject = get_post_meta( $post->ID, 'newproject', true ); //checkbox?>
                            <?php if($newproject) { //if checkbox is checked?>
                                <div id="newblock">Nieuw</div><div class="stamp checked"><?php meta('project-text'); ?></div>
                            <?php } else { //if checkbox isn't checked?>
                                <div class="stamp"><?php meta('project-text'); ?></div>
                            <?php } ?>

                        <?php $featured = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "Full"); ?>
                        <img src="<?php bloginfo('template_url');?>/thumb.php?src=<?php echo $featured[0]; ?>&amp;w=300&amp;h=200&amp;zc=1&amp;q=100&amp;" width="300" height="200" data-thumb="<?php bloginfo('template_url');?>/thumb.php?src=<?php echo $featured[0]; ?>&amp;w=300&amp;h=200&amp;zc=1&amp;q=100&amp;" alt="<?php the_title(); ?>" />
                    </div><!--/extracontent-block-image-->
                    <h3><?php the_title(); ?></h3>
                    <p>
                        <?php the_content(); ?>
                    </p>
                    <a href="<?php the_permalink(); ?>"><div class="button"><?php meta('project-button'); ?></div></a>
                </div>
            <?php endwhile; endif; wp_reset_query(); ?>

EDIT

The loop is working, I just refreshed the page and one of the checkboxed was checked, with the effect I want. Now, if I want to check one, they turn their-self off automatically again.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.