post__in not taking my list of IDs

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.

Read More

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!

Related posts

Leave a Reply

1 comment