开发者

Using wp_query to pull content from a specific post using either title or id

开发者 https://www.devze.com 2022-12-22 15:04 出处:网络
I am trying to pull excerpts and custom fields from specific posts, I have tried using post titles and post id but I am only succeeding in pulling every single post using this query. For example I hav

I am trying to pull excerpts and custom fields from specific posts, I have tried using post titles and post id but I am only succeeding in pulling every single post using this query. For example I have this code trying to pull just the title for the post with id 182

<?php $map = new WP_Query();
$map开发者_运维问答->query('post_id=182'); ?>
<?php while ($map->have_posts()) : $map->the_post(); ?
<?php the_title(); ?>
<?php endwhile; ?>

It pulls the title of every single post using this method and I can not figure out how I am going to have multiple loops like this each pulling content from just one specific post. Can someone please explain where I went wrong?


I've had luck with WP_query('p=182').


If you know the post ID then you can use get_post($post_id); like so

$post_id = 182;
$my_post = get_post($post_id);
$title = $my_post->post_title;
echo $title;
echo $my_post->post_content;

ckeckout codex

0

精彩评论

暂无评论...
验证码 换一张
取 消