logo

$10
Redirect Problem with WP_Query in an admin function

I am putting together a couple of metaboxes for a custom post type in Wordpress 3.0. Got the code working spot on in the admin panel, everything displays, saves and loads as it should but as soon as I load the front end I get this error from FF & Safari:


The page isn't redirecting properly:
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.


I have boiled it down to being caused by one function, which I am calling in order create an array of post_ID -> post_Title, to later use to populate a select box. Taking out the calls to the function fix everything, but I can't fault the function.



function mf_get_custom_post_list($type){ $post_list = array(); $meta_query = new WP_Query('post_type='.$type); if ( $meta_query->have_posts() ) : while ( $meta_query->have_posts() ) : $meta_query->the_post(); $post_list[get_the_ID()] = get_the_title(); endwhile; endif; //Reset Query wp_reset_query(); return $post_list; }


__________________

John Farrow | 07/28/10 at 7:00am | Edit


(1) Possible Answers Submitted...

Note: John Farrow felt their question was unanswered, so we granted them a refund.

Note: John Farrow requested a refund. They offered no explanation.

  • avatar
    Last edited:
    07/28/10
    7:05am
    Utkarsh Kukreti says:

    Can you post the rest of the code?

    • 07/28/10 7:19am

      John Farrow says:

      this is the script for the meta boxes

      <?php
      /*
      *
      *Meta Boxes
      *
      */

      ///*/

      function mf_SALF_get_custom_post_list($type){
      $post_list = array();
      $meta_query = new WP_Query('post_type='.$type);



      if ($meta_query->have_posts()):while($meta_query->have_posts()):$meta_query->the_post();
      $post_list[get_the_ID()] = get_the_title();
      endwhile;
      endif;

      return $post_list;
      }

      $prefix = 'mf_SALF_meta_';

      $meta_box = array(
      'id' => 'videos',
      'title' => 'date',
      'page' => 'Program',
      'context' => 'normal',
      'priority' => 'high',
      'fields' => array(

      array(
      'name' => 'Venue',
      'id' => $prefix . 'venue',
      'type' => 'select2',
      'options' => mf_SALF_get_custom_post_list('Venues')
      ),
      array(
      'name' => 'Artist',
      'id' => $prefix . 'artist',
      'type' => 'select2',
      'options' => mf_SALF_get_custom_post_list('Artists')
      )
      )
      );


      add_action('admin_menu','mf_SALF_meta_box');

      // Add meta box
      function mf_SALF_meta_box(){
      global $meta_box;

      add_meta_box($meta_box['id'], $meta_box['title'], 'mf_SALF_meta_show_box', $meta_box['page'], $meta_box['context'], $meta_box['priority']);
      }
      // Callback function to show fields in meta box
      function mf_SALF_meta_show_box() {
      global $meta_box, $post;

      // Use nonce for verification
      echo '<input type="hidden" name="mytheme_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';

      echo '<table class="form-table">';

      foreach ($meta_box['fields'] as $field) {
      // get current post meta data
      $meta = get_post_meta($post->ID, $field['id'], true);

      echo '<tr>',
      '<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>',
      '<td>';
      switch ($field['type']) {

      case 'select2':

      echo '<select name="', $field['id'], '" id="', $field['id'], '">';
      foreach ($field['options'] as $ID => $option) {
      echo '<option value="'. $ID .'" ', $meta == $ID ? ' selected="selected"' : '', '>', $option, '</option>';
      }
      echo '</select>';

      break;
      }
      echo '<td>',
      '</tr>';
      }

      echo '</table>';
      }
      add_action('save_post', 'mf_SALF_meta_save_data');

      // Save data from meta box
      function mf_SALF_meta_save_data($post_id) {
      global $meta_box;

      // verify nonce
      if (!wp_verify_nonce($_POST['mytheme_meta_box_nonce'], basename(__FILE__))) {
      return $post_id;
      }

      // check autosave
      if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
      return $post_id;
      }

      // check permissions
      if ('page' == $_POST['post_type']) {
      if (!current_user_can('edit_page', $post_id)) {
      return $post_id;
      }
      } elseif (!current_user_can('edit_post', $post_id)) {
      return $post_id;
      }

      foreach ($meta_box['fields'] as $field) {
      $old = get_post_meta($post_id, $field['id'], true);
      $new = $_POST[$field['id']];

      if ($new && $new != $old) {
      update_post_meta($post_id, $field['id'], $new);
      } elseif ('' == $new && $old) {
      delete_post_meta($post_id, $field['id'], $old);
      }
      }
      }

      ?>


      this is being called by
      include('meta.php');
      in functions.php

      I am sure it is that function at fault, as if I comment out the two calls to it, everything goes back to normal.

    • 07/28/10 7:51am

      John Farrow says:

      The more I experiment, they more I think the solution is to obtain the ID's and titles without using The Loop

    • 07/28/10 7:52am

      John Farrow says:

      But I don't know how!!

    • 07/28/10 8:52am

      Utkarsh Kukreti says:

      Could you enable this and link me to the site? (or PM)

      Need to have a look at the redirect.

    • 07/29/10 4:48am

      John Farrow says:

      unfortunately not, too much sensitive client stuff.

      I have now fixed it, so don't know where I stand here!!

This question has expired.





Current status of this question: Refunded