Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

'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
    )
)
share|improve this answer
    
+1 Nice information.. –  amit Aug 1 '12 at 19:27
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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