wp_query a single custom post type?

How does one get a custom post by id? FYI: I am passing a particular post id through a form and it’s performing an ajax call.

I’d like to retrieve just one post and grab the title:

<?php 
// E.g. $loc = 700
$args = array('post_id'=>$loc, 'post_type'=>'seminars', 'limit'=> '1');

$loop = new WP_Query($args);
// Start loop for seminar posts
$loop->the_post();
echo the_title();

// returns just one post and it's not the right custom post

2 Answers
2

'post_id' is not a valid page/post parameter for WP_Query(). Try using p or post__in instead:

array(
    'p' => 700
)

or

array(
    'post__in' => array(
        700
    )
)

Leave a Comment