谁能告诉我使用帖子 ID 获取帖子的最佳方式是什么?
我正在使用这个:
$query = query_posts('post_id='.$_GET['php_post_id']);
全局 $post;
foreach ($query as $post):
做事...
这将返回一个包含所有帖子的数组
最佳答案
get_post( $post_id, $output );
所以在实践中看起来像:
$my_id = 7;
$post_id_7 = get_post($my_id);
有关帖子参数和字段的更多引用,此处:http://codex.wordpress.org/Function_Reference/get_post
更新:当您需要通过 id 获取单个帖子时,这是最佳做法,不需要 cicles。
https://stackoverflow.com/questions/11153741/
相关文章:
css - 使用 :nth-child(odd) selector on div image
sql-server - 当命令类型为 adCmdText 时是否可以使用命名参数?
css - 可缩放字体大小,SASS (LESS) with "px"vs plain ems
jquery - 如何使用 jQuery 和 HTML5 canvas 画线
debugging - vb6 如何在 msgbox 中进入 Debug模式
jsf - 如何为 h :graphicImage Primefaces 添加操作