How to get term meta WPGraphQL/WooGraphQL?

Viewed 431

I'm using Woo GraphQL and I'm wondering how I should go about getting the color of product attributes. See below for a screenshot of the product attribute in WP Admin:

enter image description here

I've tried querying for the top-level pa- attribute and I've tried querying in terms/termNode with no luck.

Am I missing something? How do I get this data?


Update: So TIL, that colors in products attributes were actually provided via "Variation Swatches for WooCommerce". Variation Swatches takes this info and saves it in term meta.

So now my question is a bit different: How do I pull term meta?

2 Answers

The best way that I have found is to not use (or with addition to ) WooSwatches plugin us should use advanced custom fields and WPGraphQL for Advanced Custom Fields in the following way

  • add a new field groupe with name Color Hex that has the location rule Taxonomy is equal to Color (or what ever attribute you want to use)

enter image description here

  • add a field with the name hex (for example) with type of color picker and make show in graphql

enter image description here

  • you should be able to query the data like this

paColors {
  nodes {
    id
    name
    description
    colorHex {
      hex
    }
  }
}

You can get term meta using the get_term_meta() function. See more here.

I believe the meta key you want for this swatch_id.

Related