Print_r如果放置在侧边栏或single.php中,则显示两个不同的POST->ID

时间:2012-01-08 作者:Filippo Bonino

我的网站正在为同一篇文章显示两个不同的ID(如果是print\\r)。如果我问:

<?php echo $post->ID;?>
在单曲中。php它给了我一个数字。如果我在侧边栏中做同样的事情,它会给我一个完全不同的结果。

这就是我在单曲上打印的内容。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 )
这是我从侧边栏中得到的:

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 )
基本上是两个不同的职位。

注意:这件事只发生在我标记的帖子中。如果我没有标记帖子,那么生成的ID将是相同的。

Here, 你可以在我的网站上找到一个例子,print\\r为同一篇文章显示了两个不同的ID。

救命啊,这东西把我吓坏了。

谢谢

1 个回复
最合适的回答,由SO网友:helgatheviking 整理而成

你是否有一个查询将那些相关的帖子放在最下面?4个方块?

看起来您需要一个wp\\u reset\\u query(),因为最后一个方块的标题是“prova 3”,这是您在侧栏中显示对象数据的帖子。

结束

相关推荐

allow photo/video in comments

我请求允许订阅者在评论中上传/嵌入照片或视频。如果有人知道现有的插件可以处理这个问题,我找不到任何合适的插件。我找到了一些代码示例来更改从注释中剥离出来的标签,这将允许嵌入,但我不确定这是否真的符合要求,并且需要更改为核心文件。