使用帖子 ID 查询帖子 [英] Query post using post id

查看:24
本文介绍了使用帖子 ID 查询帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

S有人可以告诉我使用它的 id 获取帖子的最佳方式是什么?

SSomeone can tell me what's the best way to get a post using it's id?

我正在使用这个:

$query = query_posts('post_id='.$_GET['php_post_id']);全球$post;
foreach ($query as $post):

$query = query_posts('post_id='.$_GET['php_post_id']); global $post;
foreach ($query as $post):

做事...

这将返回一个包含所有帖子的数组

This is returning an array with all post

推荐答案

get_post( $post_id, $output );

所以在实践中看起来像:

So in practice will look like:

$my_id = 7;
$post_id_7 = get_post($my_id);

关于帖子的参数和字段的更多参考,在这里:http://codex.wordpress.org/Function_Reference/get_post

Further reference about the post's parameters and fields, here: http://codex.wordpress.org/Function_Reference/get_post

更新:这是最佳做法,当您需要通过 id 获取单个帖子时,不需要 cicle.

Update: It's the best practice when you need to get a single post by id, no cicles required.

这篇关于使用帖子 ID 查询帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆