WordPress.org

Ready to get started?Download WordPress

Forums

Post loop for specific post ids? (5 posts)

  1. blogthisnow
    Member
    Posted 1 year ago #

    I got a query made to loop for specific post ids (below).

    But when I run the loop it just displays the most recent posts.

    What can I do to fix this?

    <?php
    $post_id = array(483,486);
     $posts = get_posts( $post_id);
     foreach( $posts as $post ) :
      setup_postdata($post);  ?>
  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

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

    example:

    $posts = get_posts( array( 'post__in' => $post_id ) );
  3. blogthisnow
    Member
    Posted 1 year ago #

    What? Maybe a good answer but not very clear on what exactly you've instructed ,me to do with my code above?

  4. blogthisnow
    Member
    Posted 1 year ago #

    That doesn't work either.

    <?php
    $post_id = array(483,486);
     $posts = get_posts( array( 'post_type' => 'post', 'post__in' => $post_id ) );
     foreach( $posts as $post ) :
      setup_postdata($post);  ?>	
    
        <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
    
    						 <a class="thumb" href="<?php the_permalink(); ?>"><?php dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '" class="hthumb"'); ?></a><?php the_excerpt(45); ?><a href="<?php the_permalink(); ?>" class="more">Read More..</a><div style="clear:both;"></div>
    <?php endforeach; ?>
  5. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    what is the output, if any?

    any error messages?

    do posts 483 and 486 really exist?

    where exactly are you integrating the code?

    can you post a link to your site to illustrate the output?

    what happens is if you temporarily deactivate all plugins?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags