WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Assigned Custom Post Type ID but displays all (5 posts)

  1. ivanoconfa
    Member
    Posted 2 years ago #

    I only want to display one CPT with ID number 81 and am having a nightmare trying to understand why all my custom posts are showing on the homepage. The code is as simple as the following:

    <?php//The Query
    query_posts('post_type=Homepage&post=81'); // this should only call the Homepage custom post with ID 81
    
    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            //doing something here
    <?php endwhile; else: ?>
          //doing something here
    <?php endif;
    //Reset Query
    wp_reset_query();
    ?>

    Can anyone help? I am clearly missing something out. Thank you

  2. Is the post with ID=81 showing first in the list?

    If so, add showposts=1 to your query_post string like this:

    query_posts('post_type=Homepage&post=81&showposts=1');

    Either way, if you're only trying to show one post, make sure to set the showposts parameter to 1 in the query_posts array.

  3. ivanoconfa
    Member
    Posted 2 years ago #

    Hi, thank you. No the post ID=81 is not showing first in the list. I am familiar with showposts but I have 10 custom posts which I want to display separately on the homepage by calling their individual IDs.
    I was hoping that by creating a loop for each of them I could position them wherever I'd see fit on a page, and consequently style them differently. See below:

    <div id="square">?php
    query_posts('post_type=Homepage&post=81');
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>//doing something here
    endwhile;
    // Reset Query
    wp_reset_query();
    ?> </div>

    and then

    <div id="rectangle">?php
    query_posts('post_type=Homepage&post=84');
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>//doing something here
    endwhile;
    // Reset Query
    wp_reset_query();
    ?> </div>

    Am I approaching this completely the wrong way? At the moment the ID=81 is not calling the custom 'Homepage' post with ID 81 but it's calling ALL 'Homepage' posts. Or if I set the parameter showposts=1 it displays the latest post created. Thanks for your help.

  4. keesiemeijer
    moderator
    Posted 2 years ago #

  5. ivanoconfa
    Member
    Posted 2 years ago #

    Bingo! It worked!!
    query_posts('post_type=Homepage&p=81');
    Thanks very much!

Topic Closed

This topic has been closed to new replies.

About this Topic