2

I'm simply trying to display a specific post id from my custom post type 'homepage_video'. I'm sure that this is the correct code but it seems to be returning all of the posts rather than just Post Id 40.

<?php
                    query_posts('post_id=40&post_type=homepage_video');
                    while (have_posts()): the_post(); ?>
                        <div id="video-panel-blue">
                            <?php get_custom_field('home-video-iframe', TRUE); ?>
                        </div>
                    <?php endwhile; ?>

Thanks

1

2 Answers 2

9

post_id is not a valid argument for query_post Change post_id to p, so you get:

query_posts('p=40&post_type=homepage_video');
while (have_posts()): the_post(); ?>
    <div id="video-panel-blue">
    <?php get_custom_field('home-video-iframe', TRUE); ?>
    </div>
<?php endwhile; ?>

to see the list of arguments you can use with query_posts take a look at this codex entry

1
  • what is get_custom_field ?
    – Ari
    Sep 13, 2015 at 9:41
2

All posts, regardless of their post type, are stored in the same table in WordPress. That implies that the post ID is unique. So you don't have to use query_posts() to get a specific post, you can simply use get_post():

$my_post = get_post(40);
echo $my_post->post_title;
1
  • What if instead of post_title, I wanted to get a field?
    – Si8
    Mar 15, 2018 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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