[SOLVED] post__in just displays all the records in the post type

October 2, 2013

I have been struggling the last couple of days with a clients wordpress site where he needs to display a list of speakers (assigned to “speaker” post type) onto another post type layout called “company”.

The goal is to display a list of speakers on the company profile page. The list of speakers by the way is being held in a custom field with the company profile post type in CSV format like this 235,998,2318 etc.

I will not go into the complex nitty gritty of code I attempted to use, all I can say is that nothing related to post__in seemed to work at all. I tried with WP_Query as well as query_posts and got nowhere. I tried what felt like hundreds of forums and articles suggestions. The only results from all attempts to do it the wordpress way  was that the loop would either print out every single speaker or only the first speaker in the array or no speakers at all. It was totally maddening!

Here is my work around using normal php “for” command.

//first get the csv list of speaker id's from the custom field
$speaker_ids = get_post_meta($company_post_id, "speaker_ids", $single = true);
//loop through the speaker id's and display the posts
   $speaker_post_id = $speaker_ids[$i];
   $speaker_name = get_the_title($speaker_post_id);

Hope this helps someone and saves them some time.