0

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

3 Answers 3

1

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.

0
1

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.

1
  • Thanks for that @sanchothefat, I know I was doing it wrong somewhere. I have now edited the code which I will add above.
    – Gareth
    Commented Oct 4, 2011 at 14:47
0

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

Use get_posts(); instead.

Your Answer

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

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