2

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

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
    )
)
0
2

If you need only title then why not to use get_the_title function ?

//$post_ID = 700
<?php echo get_the_title($post_ID); ?>

There is NO way we can pass post-ID as parameter to WP_Query() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.