WordPress.org

Ready to get started?Download WordPress

Forums

Listing posts by a pre-filled Array ! (3 posts)

  1. utzutz
    Member
    Posted 3 years ago #

    Servus,

    I need to accomplish something like this:

    for ( $i = 0; $i < $darray['max']; $i++ ) {
    		$list=$darray[$i]['pID'];
    		array_push($stack,$list);
    	}
    		$args= array('p=' => $stack);
    		$temp_query = new WP_Query($args);
    		while ($temp_query->have_posts()) : $temp_query->the_post();

    This will work with pages using the codex mentioned posts__in, but how can I solve this with straight post IDs ?

    Thanks in advance!

  2. MichaelH
    Member
    Posted 3 years ago #

    You can use posts__in for posts, just put the ids in an array

    <?php
    $args=array(
      'posts__in' => array(5,12,2,14,7),
      'post_type' => 'post',
      'post_status' => 'publish',
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. utzutz
    Member
    Posted 3 years ago #

    thanks .. gonna try n report if works !

Topic Closed

This topic has been closed to new replies.

About this Topic