最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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);
发布评论

评论列表(0)

  1. 暂无评论