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.

My website is displaying, if print_r, two different ID for the same post. If i ask:

<?php echo $post->ID;?>

in the single.php it gives me a number. If i do the same thing in the sidebar it gives me a completely different one.

This is what I get with the print_r on the single.php

stdClass Object ( [ID] => 59 [post_author] => 1 [post_date] => 2012-01-01 20:29:18 
[post_date_gmt] => 2012-01-01 20:29:18 [post_content] => È universalmente
riconosciuto (...) [post_title] => fdsfdsfs [show_in_menu] => 1 [link_link] => 1
[no_follow_link] => 0 [alt_link_text] => [custom_link_class] => [redirect_url] =>
[target_blank] => 0 [alt_title_attribute] => [post_excerpt] => [post_status] => publish
[comment_status] => closed [ping_status] => closed [post_password] =>
[post_name] => fdsfdsfs [to_ping] => [pinged] => [post_modified] => 2012-01-07 19:53:44
[post_modified_gmt] => 2012-01-07 19:53:44 [post_content_filtered] =>
[post_parent] => 0 [guid] => http://www.museidibra.it/prova/?p=59 [menu_order] => 0
[post_type] => post [post_mime_type] => [comment_count] => 0
[ancestors] => Array ( ) [filter] => raw )

While this is what I get from the sidebar:

stdClass Object ( [ID] => 93 [post_author] => 1 [post_date] => 2012-01-02 08:39:29
[post_date_gmt] => 2012-01-02 08:39:29 [post_content] => prova 3 (...)
[post_title] => prova 3 [show_in_menu] => 1 [link_link] => 1 [no_follow_link] => 0
[alt_link_text] => [custom_link_class] => [redirect_url] => [target_blank] => 0
[alt_title_attribute] => [post_excerpt] => [post_status] => publish
[comment_status] => closed [ping_status] => closed [post_password] =>
[post_name] => prova-3 [to_ping] => [pinged] => [post_modified] => 2012-01-07 13:06:15
[post_modified_gmt] => 2012-01-07 13:06:15 [post_content_filtered] =>
[post_parent] => 0 [guid] => http://www.museidibra.it/prova/?p=93 [menu_order] => 0
[post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw )

It is basically 2 different posts.

NOTE: this thing happens only in post that i tagged. I f i don't tag the post, the resulting IDs will be the same.

Here, you can find an example of this from my website, where print_r shows 2 different IDs for the same post.

Help please, this thing is freaking me out.

Thanks

share|improve this question
    
Can you check museidibra.it/prova/?p=59 and museidibra.it/prova/?p=93 are same page ? –  Eray Jan 8 '12 at 22:48
1  
Can you post the code surrounding the print_r() on the sidebar, as that is the one with the ID which does not match the page. –  m0r7if3r Jan 9 '12 at 0:59
add comment

1 Answer

up vote 1 down vote accepted

do you have a query pulling those related posts at the bottom? the 4 squares?

it looks like you need a wp_reset_query() after those as the final square is titled "prova 3" which is the post you are showing the object data for in the sidebar.

share|improve this answer
    
You are so right, of course! Thanks you so much! –  Filippo Bonino Jan 9 '12 at 6:30
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.