0

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.

4
  • use a foreach!???? are you designing a custom plugin or for use with a custom plugin?
    – Bysander
    Commented Jul 21, 2014 at 17:38
  • the foreah part I do understand and yes it's my own plugin.
    – user759235
    Commented Jul 21, 2014 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
    Commented Jul 21, 2014 at 20:18
  • I would edit your question as at the moment we're not sure where you're having problems
    – Bysander
    Commented Jul 22, 2014 at 11:21

1 Answer 1

0

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:

<?php
  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 and acknowledge you have read our privacy policy.

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