WordPress.org

Ready to get started?Download WordPress

Forums

metabox error, excerpt disapper by while loop (2 posts)

  1. granskog
    Member
    Posted 1 year ago #

    Hi,
    I have made a meta_box for my custom post an in there I whant the user to choose a page or a post that the custom post will link to.
    But I have a problem. this is the function that puts all permalink i a select. But when I do this function in my meta box kode the saved excerpt disapper. I have tried it and I know it is something wrong with the while loop but what?

    function get_permalinks(){
      $query = new WP_Query( array( 'post_type' => 'post') );
      while ( $query->have_posts() ) {
        $query->the_post();
        $select_url .= "<option value='".get_permalink()."'";
        $select_url .= ">".get_permalink()."</option>";
      }
      $select_url .= "<option>Sidor</option>";
      $query = new WP_Query( array( 'post_type' => 'page') );
      while ( $query->have_posts() ) {
        $query->the_post();
        $select_url .= "<option value='".get_permalink()."'";
        $select_url .= ">".get_permalink()."</option>";
      }
      return $select_url;
    }

    Please help me/
    Granskog

  2. ianhaycox
    Member
    Posted 1 year ago #

    Initialise $select_url before the first while loop.

    E.g. $select_url = '';

    I'm assuming the <select> and </select> are prepended and appended after the call to get_permalinks().

    When developing WP code, help yourself by enabling debug to catch uninitialised errors like this.

    http://codex.wordpress.org/Debugging_in_WordPress

Topic Closed

This topic has been closed to new replies.

About this Topic