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 am creating 2 custom post types, and with the one displaying a list of the posts in #2.

I am 90% of the way there, have the select showing but can't get it populated with the custom post types posts from #2.

I am using get_posts to create the array, and then echoing into the select.

$option_list = get_pages( array( 'post_type' => 'Partners' ) );
echo '<select name="activitymeta_sel" id="activitymeta_sel">';
  foreach ($option_list as $option) {
   echo '<option value="' . $option . '">' . $option . '</option>';
  }
  echo '</select>';

I must be missing something. Can anyone spread some light on my quest.

edit: The new code is below but still not getting the list of the post types, I know I am going wrong somewhere but not sure where.

echo '<select name="activitymeta_sel" id="activitymeta_sel">';
 echo '<option value="">Select Partners</option> ';
  $pages = get_pages('post_type=Partners'); 
  foreach ( $pages as $pagg ) {
   $option = '<option value="' . $pagg->post_title . '">';
   $option .= $pagg->post_title;
   $option .= '</option>';
   echo $option;
  }
 echo '</select>';

Thanks In Advance

share|improve this question

3 Answers 3

up vote 1 down vote accepted

If 'Partners' is a custom post type, then why don't you use get_posts? Try using it...

$pages = get_posts(array('post_type' => 'partners', 'posts_per_page'=> -1, 'post_status' => 'publish'));
echo '<select name="activitymeta_sel" id="activitymeta_sel">';
echo '<option value="">Select Partners</option> ';

foreach ( $pages as $page ) {
   $option = '<option value="' . $page->post_title . '">';
   $option .= $page->post_title;
   $option .= '</option>';
   echo $option;
  }
 echo '</select>';

Try this. This should work.

share|improve this answer
    
Perfecto, thanks so much.. All working fine. –  Gareth Oct 4 '11 at 16:42
    
Awesomo! You're welcome! –  Rutwick Gangurde Oct 4 '11 at 16:44

You should look at the contents of $option before you try echoing it out. It contains all the post data including the content etc... so you're actually trying to echo out an object which won't do anything.

You can view the the content of the $option variable using print_r( $option ); in your foreach loop.

You'll find you need to echo out one of the properties eg. $option->post_slug or $option->post_title in your loop.

share|improve this answer
    
Thanks for that @sanchothefat, I know I was doing it wrong somewhere. I have now edited the code which I will add above. –  Gareth Oct 4 '11 at 14:47

get_pages(); Doesn't seem to be supporting Custom Type Posts lately.

Use get_posts(); instead.

share|improve this answer

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.