Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Quick explanation : When I add a new "Company" (custom post type), I have a drop down menu listing all the companies to choose if the one i'm creating depends from another one. I got 3 metaboxes, the dropdown is in the first one.

In functions.php :
<select value="<?php echo $subsidiary; ?>" name="subsidiary">
<?php
$args = array( 'post_type' => 'company');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<option value="<?php echo the_ID(); ?>" ><?php the_title() ?></option>
<?php
endwhile;
?>
</select>

The dropdown is listing all the companies as i want, but when i create a new company, all fields located after my dropdown take the values from the first company in my list, and i can't change them. Any clues?

Thanks in advance.

share|improve this question
add comment

1 Answer

When you're calling $loop->the_post(), you're replacing the global $post instance. You need to call wp_reset_postdata() after your while loop.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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