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 implementing a scrolling horizontal template and this is the code to divs that are the pages of the template.

 <?php for($i=1;$i<=2;$i++) { ?>
<div class="container" id="page-<?php echo $i ?>">
    <div class="left278">
        <?php 
            $specialPosts = new WP_Query();
            $specialPosts->query('pagename=page-'.$i.'');

            $mykey_values = get_post_custom_values('custom_select');
                foreach ( $mykey_values as $key => $value ) {
                    if ($value='one') { 
                       include 'templates/slideshow-template.php'; }
                    else if ($value=='two') { 
                       include 'templates/full-page.php'; 
                }  ?>
    </div>
</div>
<?php } ?>

As you can see I get the page name, and I have a custom field where you can choose the template page.

The problem is that it get always the custom field value of the first page. So if i choose option one in the first page and option two in the second page it shows always the first template.

How can I fix that?

share|improve this question
add comment

1 Answer 1

You must pass the $post->ID to the function or setting up the current post via a call to $specialPosts->the_post() that fills it for you

See get_post_custom_values documentation in the codex or this page on how to use it.

Try

<?php 
            $specialPosts = new WP_Query();
            $specialPosts->query('pagename=page-'.$i.'');

            while($specialPosts->have_posts()): $specialPosts->the_post();

               $mykey_values = get_post_custom_values('custom_select');
                   foreach ( $mykey_values as $key => $value ) {

            ...
            endwhile;
share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.