• Resolved seanjacob

    (@seanjacob)


    I know how to show the latest posts, but I want to get 3 posts by calling their IDs.

    <?php
    $lastposts = get_posts('numberposts=12');
    foreach($lastposts as $post) :
    setup_postdata($post);
    ?>

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • try the ‘post__in’ parameter:

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

    the query parameters are supposed to work with ‘get_posts()’ as well.

    for example:

    <?php
    $args = array(
    'numberposts' => 12,
    'post__in' => array( 3, 17, 234)
    );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) :
    setup_postdata($post);
    ?>
    Thread Starter seanjacob

    (@seanjacob)

    Thanks alchymyth, I manage to get the posts I want but I am having trouble displaying them in the order I input them in.

    <?php
    $the_query = new WP_Query( array( 'post__in' => array( 44, 18, 36 ), 'orderby' => 'none' ) );
    if( have_posts() ) :
    while ($the_query->have_posts()) : $the_query->the_post();
    ?>

    Any ideas?

    you may need to use three ‘get_post()’ functions –
    afaik, there is no way to have the posts show in any particular order, other than the ones provided by the query (date, title, ..)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to show certain posts on a page?’ is closed to new replies.