【发布时间】:2012-06-27 09:57:03
【问题描述】:
我有一个名为“Portfolio”的帖子类型和一个单独的 portfolio.php 文件来处理它(它是 WordPress)。当我在那里使用类似的东西时,它会像预期的那样工作:
$post_id = $post->ID; //returns ID of current portfolio post. Good!
但是当我在中间发布这样的简短查询时:
$post_id = $post->ID; //returns ID of current portfolio post. Good!
wp_reset_query();
query_posts('posts_per_page=4');
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_id(); //returns ID of standard blog post
endwhile;
endif;
wp_reset_query();
$post_id = $post->ID; //returns ID of last BLOG post. Wrong!
我只关心上面示例中的$post_id 变量。我希望它始终返回当前 PORTFOLIO 帖子的正确 ID,而不依赖于其他查询。我该如何实现?
【问题讨论】:
-
我找到了一种使用 $temp = $post; 的方法和 $post = $temp;查询后,但我认为这不是官方推荐的方式。