• I’ve been asked to add a feature to a site whereby users can select pages within a custom taxonomy to be assigned as related to a post.

    The function I’m using to display the pages is:

    function display_factsheets() {
      ?>
     <p><label>Related Factsheets:</label><br />
     <select multiple="multiple" style="padding:2px;font-size:11px;height:auto;" name="related_factsheets[]">
    	<?php $factsheets = new WP_Query((array('content-type' => 'factsheet')));
    		while ($factsheets->have_posts()) : $factsheets->the_post(); ?>
    		<option value="<?php echo $post->ID; ?>"><?php echo $post->ID; ?></option>
    		<?php endwhile; ?>
    </select>
    	</p>
      <?php } ?>

    And the inputs is saved to the DB using

    function save_related_factsheets(){
    	$related_factsheets=$_POST['related_factsheets'];
    	if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ):
    	if($related_factsheets):
    	die("Array has values");
    	endif;
    	endif;
    	update_post_meta($post->ID, "related_factsheets", $related_factsheets);
    	//endif;
    	}

    The custom metaBox that holds the list is

    function reachOut_metaBoxInit(){
      add_meta_box("related_factsheet", "Related Factsheets", "related_factsheets", "post", "normal", "low");
      add_meta_box("related_factsheet", "Related Factsheets", "related_factsheets", "page", "normal", "low");
    }

    And the actions are added as

    add_action("admin_init", "reachOut_metaBoxInit");
    add_action('save_post', 'save_related_factsheets');

    The issue is if I create a Page and assign it to the custom taxonomy “Factsheet” when I go to Create Post the Title, URL & Content have been filled in with the information from the most recent Factsheet. THe issue doesn’t occur on create Page though. Can anyone help me run the query to get the factsheets without interfering with the create Post Fields? I’ve tried adding wp_reset_query(); after the while in display_factsheets but it just causes the Create Posts page to not load at all.

Viewing 1 replies (of 1 total)
  • Thread Starter tpohare

    (@tpohare)

    As an add-on to this, there’s no issue at all if there are no pages set as Factsheets

Viewing 1 replies (of 1 total)
  • The topic ‘query_posts inside wp-admin Create Posts’ is closed to new replies.