WordPress.org

Forums

Custom Multiple Query_posts ID's (3 posts)

  1. rockaj
    Member
    Posted 4 years ago #

    Hello, I want to display specific posts that I choose by id. I went to that link like many times,and I suck LINK
    I can't figure out how to get multiple post ID's to show up on the custom query page.

    Below the code is working allowing me to post one postID#1033

    <?php
    query_posts('p=1033');
    while (have_posts()) : the_post();
    endwhile;
    ?>

    but i want to post more than 1, multiple postIDs so i tried the code below but not working

    <?php
    query_posts('p=1033,232,143,110,12');
    while (have_posts()) : the_post();
    endwhile;
    ?>

    please help thank you..

  2. alchymyth
    Forum Moderator
    Posted 4 years ago #

    http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters

    try:

    query_posts( array('post__in' => array(1033,232,143,110,12)) );

    (the posts will be sorted by date descending, if you don't specifiy anything else)

    if you need the posts to show in your given order, you could try:

    <?php
    $post_list = array(1033,232,143,110,12);
    foreach( $post_list as $post_id ) :
    query_posts('p='.$post_id);
    while (have_posts()) : the_post();
    endwhile;
    wp_reset_query();
    endforeach;
    ?>

    (untested)

  3. rockaj
    Member
    Posted 4 years ago #

    hello,thanks for your reply! ALCHYMYTH your a LEGEND! cheers :)

Topic Closed

This topic has been closed to new replies.

About this Topic