Support » Fixing WordPress » Custom Multiple Query_posts ID's

  • 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..

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    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)

    hello,thanks for your reply! ALCHYMYTH your a LEGEND! cheers 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Multiple Query_posts ID's’ is closed to new replies.