SSomeone can tell me what’s the best way to get a post using it’s id?
I’am using this:
$query = query_posts(‘post_id=’.$_GET[‘php_post_id’]);
global $post;
foreach ($query as $post):
do stuff…
This is returning an array with all post
SSomeone can tell me what’s the best way to get a post using it’s id?
I’am using this:
$query = query_posts(‘post_id=’.$_GET[‘php_post_id’]);
global $post;
foreach ($query as $post):
do stuff…
This is returning an array with all post
You must be logged in to post a comment.
So in practice will look like:
Further reference about the post’s parameters and fields, here: http://codex.wordpress.org/Function_Reference/get_post
Update: It’s the best practice when you need to get a single post by id, no cicles required.
Change
post_id=
top=
.Click in this link to see: Retrieve a Particular Post
If you are looking to get a single post with an ID you already know or getting from another source, i’ll suggest the below code.
You can create a query like so:
And then you can retrieve the post from the query. Or set it to the global query and loop over it:
Here is the code to fetch post using query_post if you know the ID.