Title: Echo taxonomy select value
Last modified: March 7, 2018

---

# Echo taxonomy select value

 *  Resolved [Begin](https://wordpress.org/support/users/bentalgad/)
 * (@bentalgad)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/echo-taxonomy-select-value/)
 * I know that to echo a value of select field i use:
    `$options = protags_taxonomy();
   $key = get_post_meta($listmesettings_id,'_lmsets_names_maintagshow', true ); 
   echo isset( $options[ $key ] ) ? $options[ $key ] : $options[' '];`
 * I understand protags_taxonomy() is getting the options, but how do i do that 
   when i use taxonomy as the options for a select field?

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [8 years, 3 months ago](https://wordpress.org/support/topic/echo-taxonomy-select-value/#post-10050006)
 * Not quite following, based on what you’ve provided so far.
 * What would help is knowing and preferably seeing an example of what is getting
   stored in the `$options` variable, and what the `$key` value is. Also beneficial
   is the CMB2 config so we could at least implement ourselves and tinker with what
   gets saved.
 *  Thread Starter [Begin](https://wordpress.org/support/users/bentalgad/)
 * (@bentalgad)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/echo-taxonomy-select-value/#post-10052007)
 * If it was a reguler select (not taxonomy select), for example:
 *     ```
       $workdays_box->add_field( array(
       'name' => 'ימי עבודה '.$i,
       'id' => '_pf_workdays'.$i,
       'type' => 'select',
       'default' => ' ',
       'options_cb'       => 'workdays_select_options',
       ) );
   
       function workdays_select_options() {
       return array(' ' => ' ','Mo, Tu, We, Th, Su' => 'ראשון - חמישי','Mo, Tu, We, Th, Fr, Su' => 'ראשון - שישי','Tu, Su' => 'ראשון ושלישי','Mo, We' => 'שני ורביעי','Su' => 'ראשון','Mo' => 'שני','Tu' => 'שלישי','We' => 'רביעי','Th' => 'חמישי','Fr' => 'שישי','Fr Plus' => 'שישי וערבי חג','Sa' => 'מוצ״ש',);
       }
       ```
   
 * and i would want to echo the value of the selected option i know i would use:
   `
   $options = workdays_select_options(); $key = get_post_meta( $post->ID, '_pf_workdays'.
   $wdi, true ); echo isset( $options[ $key ] ) ? $options[ $key ] : $options[' '];`
 * where `workdays_select_options()` is the function that i use in the config to
   echo the options of the select field.
 * Now i use select_taxonomy field, and the field config i use is:
 *     ```
       $lmsets_names_box->add_field( array(
       'name' => 'maintag',
       'id' => '_lmsets_names_maintagshow',
       'taxonomy'       => 'protags_taxonomy',
       'type'           => 'taxonomy_select',
       ) );
       ```
   
 * where `protags_taxonmy` is the slug of the taxonomy i want to use it’s terms 
   as options for that select field.
 * How would i echo the value of option selected in that field?
    -  This reply was modified 8 years, 3 months ago by [Begin](https://wordpress.org/support/users/bentalgad/).
    -  This reply was modified 8 years, 3 months ago by [Begin](https://wordpress.org/support/users/bentalgad/).
 *  Thread Starter [Begin](https://wordpress.org/support/users/bentalgad/)
 * (@bentalgad)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/echo-taxonomy-select-value/#post-10052036)
 * Just notice that i edited last post (incase you get the first version by mail).
   thanks.
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [8 years, 3 months ago](https://wordpress.org/support/topic/echo-taxonomy-select-value/#post-10053264)
 * Ah, I see the problem.
 * Note next to the field types that start with “taxonomy_”:
 *     ```
       * Default Category/Tag/Taxonomy metaboxes replacement.
       ```
   
 * So while yes, they are conveniently providing a list of terms that you can select
   and save based on the taxonomy provided, it is meant to be a replacement of the
   default term assignment metaboxes, and simply sets the terms for the post. It
   does NOT store the selections as post meta or term meta like you’re expecting.
 * I would look at [https://github.com/CMB2/CMB2/wiki/Tips-&-Tricks#a-dropdown-for-taxonomy-terms-which-does-not-set-the-term-on-the-post](https://github.com/CMB2/CMB2/wiki/Tips-&-Tricks#a-dropdown-for-taxonomy-terms-which-does-not-set-the-term-on-the-post)
   and see where this takes you.
 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/echo-taxonomy-select-value/#post-10053708)
 * Michael is right, but you don’t need to create a custom field type if you want
   to get access to the taxonomy term values. You would use the built-in term-getting
   functions, e.g. `$terms = get_the_terms( $post->ID, 'protags_taxonomy' );`.
 * [https://developer.wordpress.org/reference/functions/get_the_terms/](https://developer.wordpress.org/reference/functions/get_the_terms/)
 *  Thread Starter [Begin](https://wordpress.org/support/users/bentalgad/)
 * (@bentalgad)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/echo-taxonomy-select-value/#post-10054277)
 * Thanks. Ended with:
    `get_terms( array('taxonomy' => 'protags_taxonomy','fields'
   => 'id=>name',) );`
 * (Both for the config options and for the echoing code).
    -  This reply was modified 8 years, 3 months ago by [Begin](https://wordpress.org/support/users/bentalgad/).
 *  [elisafern](https://wordpress.org/support/users/elisafern/)
 * (@elisafern)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/echo-taxonomy-select-value/#post-10076703)
 * Hi there!
 * You are writing at a good time as Im having this issue – If I understand correctly,
   you are using the taxonomy_select (which DOES save the term to an object/custom
   post type, but does not save a term_id if I understood the doc) and you are able
   to retrieve the value?
 * In my case:
    I have a custom post type _Artworks_ with a _Artist_ custom taxonomy,
   and I’m using the **taxonomy_select** to attach Artists to Artworks but I would
   like to retrieve the name of the Artist.
 * I tried the solution with get_the_terms but Im not getting anything, just and
   empty Array. Did I understand correctly your initial issue?
 * Thank you!
    -  This reply was modified 8 years, 2 months ago by [elisafern](https://wordpress.org/support/users/elisafern/).
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [8 years, 2 months ago](https://wordpress.org/support/topic/echo-taxonomy-select-value/#post-10078074)
 * [@elisafern](https://wordpress.org/support/users/elisafern/)
 * Essentially taxonomy_* field types are replacements for the default metaboxes
   for categories/tags/taxonomies, and save the data in the exact same way: as terms
   on the post. It doesn’t save anything as post meta.
 * So that means all of the term/taxonomy based functions that you can use to get
   content/info from a post would still work.
 * Not quite sure why you’re receiving an empty array, as `get_the_terms` has this
   for its return types:
 * Array of WP_Term objects on success, false if there are no terms or the post 
   does not exist, WP_Error on failure.
 *  [elisafern](https://wordpress.org/support/users/elisafern/)
 * (@elisafern)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/echo-taxonomy-select-value/#post-10080608)
 * Hey Michael!
 * I noticed an error I made in the loop and now it is working great.
    Very Happy!
 * Thanks again to all! 😉
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [8 years, 2 months ago](https://wordpress.org/support/topic/echo-taxonomy-select-value/#post-10080649)
 * Another satisfied customer *fist pumps*

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Echo taxonomy select value’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

## Tags

 * [select](https://wordpress.org/support/topic-tag/select/)
 * [taxonomy](https://wordpress.org/support/topic-tag/taxonomy/)

 * 10 replies
 * 4 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/echo-taxonomy-select-value/#post-10080649)
 * Status: resolved