0
votes

I'm not a developer - I've researched this and just can't figure it out. Many thanks for any help you can give me!

I am trying to get the product attribute AND the attribute description. (I'm using this to create custom variables to use in my Follow-Up Emails.)

I am able to get the attribute name with this:

global $product;
$venuearr = wc_get_product_terms( 16624, 'pa_venue', array( 'fields' => 'names' ) );

But if I change names to descriptions, it doesn't work.

global $product;
$venuearr = wc_get_product_terms( 16624, 'pa_venue', array( 'fields' => 'descriptions' ) );

If I change names to all, I can see the attribute (pa_venue) description, but I can't get it to retrieve on its own. What am I doing wrong?

Array ( [0] => WP_Term Object ( [term_id] => 417 [name] => DiMenna Center for Classical Music [slug] => dimenna-center-for-classical-music [term_group] => 0 [term_taxonomy_id] => 417 [taxonomy] => pa_venue [description] => test [parent] => 0 [count] => 1 [filter] => raw ) )

1

1 Answers

0
votes

Accessing description directly as a fields option is not possible. ( slug, name, ids are possible )

 *     @type string       $fields                 Term fields to query for. Accepts:
 *                                                - 'all' Returns an array of complete term objects (`WP_Term[]`).
 *                                                - 'all_with_object_id' Returns an array of term objects with the 'object_id'
 *                                                  param (`WP_Term[]`). Works only when the `$object_ids` parameter is populated.
 *                                                - 'ids' Returns an array of term IDs (`int[]`).
 *                                                - 'tt_ids' Returns an array of term taxonomy IDs (`int[]`).
 *                                                - 'names' Returns an array of term names (`string[]`).
 *                                                - 'slugs' Returns an array of term slugs (`string[]`).
 *                                                - 'count' Returns the number of matching terms (`int`).
 *                                                - 'id=>parent' Returns an associative array of parent term IDs, keyed by term ID (`int[]`).
 *                                                - 'id=>name' Returns an associative array of term names, keyed by term ID (`string[]`).
 *                                                - 'id=>slug' Returns an associative array of term slugs, keyed by term ID (`string[]`).
 *                                                Default 'all'.

You can see the supported args for fields here.

See WP_Term_Query::__construct() for supported arguments.