views:

36

answers:

1

Hi,

I'm trying to use a custom field in which I input the post ID numbers of the posts I want to show, seperated by commas. For some reason though, only the first post of the series of the post IDs are displaying. Can someone help? The value of $nlPostIds is (minus the quotes): "1542,1534,1546". Here's the code... the most important part is the 4th line 'post__in' => array($nlPostIds)

<?php 
$nlPostIds = get_post_meta($post->ID, 'nlPostIds', true);
$args=array(
    'post__in' => array($nlPostIds)
   );
query_posts($args);
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

<div class="entry">
            <div class="post" id="post-<?php the_ID(); ?>">
                <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<div class="allinfos"><span class="date"><?php the_time('F jS, Y') ?></span> | <span class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> </span> | <span class="category">Posted in <?php the_category(', ') ?></span> <!-- by <?php the_author() ?> --></div>

                    <?php the_content('More &raquo;'); ?>

<?php the_tags('Tags: ', ', ', ' '); ?> <?php edit_post_link('Edit', '[ ', ' ]'); ?>
<div class="clear"></div>
</div></div>
<?php endwhile; endif; ?>

Thanks!

+1  A: 

I think you need to also pass the argument 'posts_per_page' as -1 in your $args array (see the Codex on query_posts()).

UPDATE:

Apologies, I've just re-read your question and I think I know the problem. Pass $nlPostIds as the direct argument, without placing it an array. You only pass an array when each element is an ID. In this care you're just passing a comma-separated string.

UPDATE:

Use;

$args = array('post__in' => @explode(',', $nlPostIds), 'posts_per_page' => -1);
TheDeadMedic
thanks deadmedic, but that didn't seem to do anything unfortunately
j-man86
Check my revised answer - that should do the trick :)
TheDeadMedic
Sorry, my comment might have been a bit confusing - just to confirm, you did; `$args = array('post__in' => $nlPostIds)`, not; `$args = $nlPostIds`?
TheDeadMedic
Yea... I get the following error–Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/pitchand/public_html/wp-includes/query.php on line 1706
j-man86
for the following <code>$args=array( 'post__in' => $nlPostIds );</code>
j-man86
In which case, we might get there with this; `$args = array('post__in' => @explode(',', $nlPostIds))`
TheDeadMedic
That works great, thanks! I didn't need the 'posts_per_page' argument though.
j-man86