Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a Custom Field on a page named banner_id_list.

I have a Custom Post Type called top_banner. I add a few banners, note the IDs and then go back to the page and add a comma delimited list of IDs in the banner_id_list custom field.

In my template, the plan is to check the current posts meta using get_post_meta(). That should produce a list of IDs that I can then take and use in get_posts() with post__in = array() (see post__in).

Now on to the code, I'm missing something here but I'm a bit of a newb at this.

// get the banner_id_list based on the meta custom field for this page
$banner_id_list = get_post_meta($post->ID, 'banner_id_list', true);

If I dump that I see the expected data, a list of IDs I entered into the custom field.

Now for my query:

$args = array(
    'post_type' => 'top_banner',
    'post_status' => 'publish',
    'numberposts' => -1,        
    'order' => ASC,
    'orderby' => menu_order,
    'post__in' => array($banner_id_list)
 ); 

 $banners = get_posts($args);

But there's something funky about using $banner_id_list here. It's only getting a single record. But if I manually enter values in place of that variable, it works properly.

I think it's something simple/fundamental I'm missing, hope someone can help!

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

If $banner_id_list holds comma-delimited list then to convert it to array instead of

array($banner_id_list)

you need to do

explode(',', $banner_id_list)
share|improve this answer
    
Awesome, thanks! –  jyoseph Jun 24 '11 at 20:49
2  
or wp_parse_id_list (does some extra checks) –  onetrickpony Jun 24 '11 at 20:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.