My custom post type name is movie_reviews. Inside movie reviews there are multiple post but i need only that post whose id is 244. My code for it is
<?php
$my_query = new WP_Query('post_type=movie_reviews&ID=244');
while ($my_query->have_posts()) : $my_query->the_post();
the_content();
endwhile ?>
My custom post type name is movie_reviews. Inside movie reviews there are multiple post but i need only that post whose id is 244. My code for it is
<?php
$my_query = new WP_Query('post_type=movie_reviews&ID=244');
while ($my_query->have_posts()) : $my_query->the_post();
the_content();
endwhile ?>
Share
Improve this question
asked Jul 15, 2014 at 11:08
benimubbenimub
231 gold badge1 silver badge4 bronze badges
2 Answers
Reset to default 14Have a look at the Post & Page Parameters Section in the WP_Query
Documentation
For getting a Post by Post ID, you need to use this:
$my_query = new WP_Query('post_type=movie_reviews&p=244');
If you only need the content of one specific post, you can also do this:
$mypost = get_post(244);
echo apply_filters('the_content',$mypost->post_content);
In this case, you don't need to worry about the loop or the global vars getting overwritten, removing your main loop.
If you wanna use in loop and use for each post
$mypost = get_post($post->ID);
echo apply_filters('the_content',$mypost->post_content);