php - How do I get content of custom post type through post ID in wordpress

My custom post type name is movie_reviews. Inside movie reviews there are multiple post but i need only that post whose

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
Add a comment  | 

2 Answers 2

Reset to default 14

Have 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);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744653421a4586038.html

相关推荐

  • php - How do I get content of custom post type through post ID in wordpress

    My custom post type name is movie_reviews. Inside movie reviews there are multiple post but i need only that post whose

    2天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信