• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 29
  • Last Modified:

Wordpress get taxonomy terms

Wordpress Get Taxonomy names and slugs
I'm trying to get all of the terms for a specific taxonomy and have followed the dirrections but I end up with an empty select dropdown: It does show the default placeholder in the Select though.

function tlg_variation_warehouse_fields( $loop, $variation_data, $variation ) {
	// Select
        global $wpdb;
      $taxonomy = 'pa_variable-warehouse';
      // Get the selected value  <== <== (updated)
    $value = get_post_meta( $post->ID, '_select', true );
    if( empty( $value ) ) $value = '';
 $get_terms = get_terms($taxonomy, array (
          'hide_empty' => false,
'orderby' => 'term_id',
            'order' => 'ASC'

  $options[''] = __( 'Select a Location', 'woocommerce'); // default value
	    echo '<div class="options_group">';

    woocommerce_wp_select( array(
        'id'      => '_select',
        'label'   => __( 'Warehose Location', 'woocommerce' ),
        'options' =>  $options, //this is where I am having trouble
        'value'   => $value,
    ) );

    echo '</div>';

Open in new window

1 Solution
It doesn't look like you ever add your $get_terms data to the $options array.

I'm guessing you should probably do something like:

$options[''] = __( 'Select a Location', 'woocommerce'); // default value

foreach($get_terms as $term)
  $options[$term->term_id] = $term->name;

echo '<div class="options_group">';

Open in new window

rgranlundAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now