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 have been building a series of theme pages. On one page a users messages (post_type=messages) come in in a tab on the page. The content is displayed in place as is the title etc.... The content is shown again after the closing on the page. There is no that would let that happen in the theme.

Furthermore the post_type=bookings that show up in another tab echo the content correctly. But within that loop is another loop that shows the post_type=items showing the configurations of each booking. It then echoes the last item as another booking.

What the hell is going on.

Any ideas?

Marvellous

---- EDIT ---

The error is due to loops within loops. So we need to use the get_posts function instead of query_posts. I have implemented it like this.

<?php $congigs = get_posts('post_type=items&author='.$current_user->ID.'&tag='.$bkpostid.'&numberposts=-1');
                    foreach($congigs as $posts) :  setup_postdata($posts); ?> <li><?php the_title(); ?></li>
<?php endforeach; ?>

There should be 8 of these posts to get and it does get them, however <? the title ?> is showing 8 copies of the main title of the entire page, not the item post title.

Any ideas. Thanks,

share|improve this question
1  
Please provide the code used for the loop that is causing the problem. –  John P Bloch Feb 23 '11 at 14:40
    
The error I have just worked out is due to loops within loops. The question will now be edited –  Robin I Knight Feb 23 '11 at 14:51
    
Change each occurance of $posts to $post. –  t31os Feb 23 '11 at 15:52
    
@t31os, thanks for your help but that would not be quite correct. Changing $posts to $post would make no difference as it is supposed to be a unique identifier. There is another one where I called it $messages. Provided that they are all the same. The last thing I would want to do is to use $post as it increases the chance of conflict. –  Robin I Knight Feb 23 '11 at 16:27
1  
That particular function will only work properly when using $post, i'm not sure why, it's something to do with how the template tags work(but your code will work when using $post instead of $posts), try it. –  t31os Feb 23 '11 at 16:42

2 Answers 2

<?php $congigs = get_posts('post_type=items&author='.$current_user->ID.'&tag='.$bkpostid.'&numberposts=-1');
                    foreach($congigs as $posts) :  $title = $posts->post_title; ?> <li><?php echo $title; ?></li>
<?php endforeach; ?>
share|improve this answer
    
is this the correct answer? Please elaborate. –  Chris_O Apr 24 '11 at 23:15

Try writing wp_reset_query(); right after your main loop. You can also try looking into the WP_Query:

// write this at the top of the file  
global $wp_query;  
print_r( $wp_query );  

// then try to look at what exactly you're calling:  
// after $congigs = get_posts(...):  
print_r( $congigs );
// inside foreach ( $congigs...
print_r( $posts );
share|improve this answer

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.