0

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 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

6 Comments

thanks deadmedic, but that didn't seem to do anything unfortunately
Sorry, my comment might have been a bit confusing - just to confirm, you did; $args = array('post__in' => $nlPostIds), not; $args = $nlPostIds?
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
for the following <code>$args=array( 'post__in' => $nlPostIds );</code>
In which case, we might get there with this; $args = array('post__in' => @explode(',', $nlPostIds))
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.