So I'm looking for a way to show all posts/pages inside a multiple selectbox, which is used to select and store which page/posts has been checked in order to display some text on that page(custom plugin).

I'm looking to get the id of the posts/pages so that I can save these and use on the frontend of the templates. I did use get_pages() but these dont output anykind of page id.

  • use a foreach!???? are you designing a custom plugin or for use with a custom plugin? – Bysander Jul 21 '14 at 17:38
  • the foreah part I do understand and yes it's my own plugin. – user759235 Jul 21 '14 at 19:40
  • 2
    You need to post way more information about this question if you expect to get an answer. And take a look at WP_QUERY – gdaniel Jul 21 '14 at 20:18
  • I would edit your question as at the moment we're not sure where you're having problems – Bysander Jul 22 '14 at 11:21

get_pages returns an array of post objects, so you would use foreach to iterate over each object and grab the ID and whatever else you want to use:

  if ( $pages = get_pages( $args ) {
    echo "<select multiple>";
    foreach ( $pages as $page ) {
      echo "<option value='{$page->ID}'>{$page->post_title}</option>";
    echo "</select>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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