I have a select dropdown in my post meta in which I am getting post ids of all post of another custom post type. see below code-

    <select name="property_type" id="property_type">
               <option value=""></option>
                  'post_type' => "soto_propertyType",
                  'post_status' => 'publish',
                  'posts_per_page' => -1,
                  'order' =>'ASC',

               $propertyType_query = null;
               $propertyType_query = new WP_Query($propertyType_args);
               if( $propertyType_query->have_posts() ) {
                  while ($propertyType_query->have_posts()) : $propertyType_query->the_post(); 
                  <option value="<?php echo the_ID(); ?>" <?php selected( $property_type, the_ID(), false ); ?>><?php echo the_title(); ?></option>

In this select list I am getting all ids of all post but not getting existing value as selected in option. I am getting select dropdown like this-

enter image description here

What I have to do to show existing value as selected in dropdown list. Please help me.

1 Answer 1


the_ID() echoes its value, you can't use it in that context. Change it to get_the_ID().

Many functions in WordPress follow this pattern- one function will print, while the same function with get_ prepended will return its value.

  • @shashank Please revisit this answer and accept it as it seems that the solution worked. :-) Mar 3, 2015 at 18:04

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.