Skip to main content
edited tags
Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459
added 553 characters in body
Source Link
Anagio
  • 953
  • 3
  • 20
  • 47

I'm using this code to get the term_id of a custom taxonomy. The drop down does list the terms of the taxonomy Type. When I print the $terms variable I see the term ID of the post i'm editing on the front end. Why isn't the term ID being set as the selected option?

$terms = get_the_terms( $current_post, 'Type' );
print_r($terms);
wp_dropdown_categories( 'taxonomy=Type&hierarchical=1&hide_empty=0&id=cat&show_count=0&selected=' . $terms[0]->term_id );

This is the output of the array

Array ( [25] => stdClass Object ( [term_id] => 25 [name] => Sativa [slug] => sativa [term_group] => 0 [term_icon] => http://pothwy.com/wp-content/themes/GeoPlaces/images/default.png [term_price] => 0 [term_taxonomy_id] => 53 [taxonomy] => Type [description] => [parent] => 0 [count] => 4 [object_id] => 563 ) )

Output of HTML

<select name="cat" id="cat" class="postform">
    <option class="level-0" value="25">Sativa</option>
    <option class="level-0" value="52">Indica</option>
</select>

I'm using this code to get the term_id of a custom taxonomy. The drop down does list the terms of the taxonomy Type. When I print the $terms variable I see the term ID of the post i'm editing on the front end. Why isn't the term ID being set as the selected option?

$terms = get_the_terms( $current_post, 'Type' );
print_r($terms);
wp_dropdown_categories( 'taxonomy=Type&hierarchical=1&hide_empty=0&id=cat&show_count=0&selected=' . $terms[0]->term_id );

I'm using this code to get the term_id of a custom taxonomy. The drop down does list the terms of the taxonomy Type. When I print the $terms variable I see the term ID of the post i'm editing on the front end. Why isn't the term ID being set as the selected option?

$terms = get_the_terms( $current_post, 'Type' );
print_r($terms);
wp_dropdown_categories( 'taxonomy=Type&hierarchical=1&hide_empty=0&id=cat&show_count=0&selected=' . $terms[0]->term_id );

This is the output of the array

Array ( [25] => stdClass Object ( [term_id] => 25 [name] => Sativa [slug] => sativa [term_group] => 0 [term_icon] => http://pothwy.com/wp-content/themes/GeoPlaces/images/default.png [term_price] => 0 [term_taxonomy_id] => 53 [taxonomy] => Type [description] => [parent] => 0 [count] => 4 [object_id] => 563 ) )

Output of HTML

<select name="cat" id="cat" class="postform">
    <option class="level-0" value="25">Sativa</option>
    <option class="level-0" value="52">Indica</option>
</select>
Rollback to Revision 1
Source Link
Anagio
  • 953
  • 3
  • 20
  • 47

I'm using this code to get the term_id of a custom taxonomy. The drop down does list the terms of the taxonomy Type. When I print the $terms variable I see the term ID of the post i'm editing on the front end. Why isn't the term ID being set as the selected option?

<?php
$terms = get_the_terms( $current_post, 'Type' );
print_r($terms);
$args = arraywp_dropdown_categories(
    'taxonomy' => 'Type',
    'hierarchical' => 1,
    'hide_empty' => 0,
    'id' => 'cat',
    'show_count' => 0,
    'selected''taxonomy=Type&hierarchical=1&hide_empty=0&id=cat&show_count=0&selected=' =>. $terms[0]->term_id
    );
wp_dropdown_categories($args);

I'm using this code to get the term_id of a custom taxonomy. The drop down does list the terms of the taxonomy Type. When I print the $terms variable I see the term ID of the post i'm editing on the front end. Why isn't the term ID being set as the selected option?

<?php
$terms = get_the_terms( $current_post, 'Type' );
print_r($terms);
$args = array(
    'taxonomy' => 'Type',
    'hierarchical' => 1,
    'hide_empty' => 0,
    'id' => 'cat',
    'show_count' => 0,
    'selected' => $terms[0]->term_id
    );
wp_dropdown_categories($args);

I'm using this code to get the term_id of a custom taxonomy. The drop down does list the terms of the taxonomy Type. When I print the $terms variable I see the term ID of the post i'm editing on the front end. Why isn't the term ID being set as the selected option?

$terms = get_the_terms( $current_post, 'Type' );
print_r($terms);
wp_dropdown_categories( 'taxonomy=Type&hierarchical=1&hide_empty=0&id=cat&show_count=0&selected=' . $terms[0]->term_id );
Source Link
Anagio
  • 953
  • 3
  • 20
  • 47
Loading