PageSourceSearch

https://docs.builderius.io/assets/js/cac4308d.a70aba95.js

js builderius.io collected 2026-10-02 04:56:10 UTC 35,666 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkbuilderius=globalThis.webpackChunkbuilderius||[]).push([[6059],{5590:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>u,contentTitle:()=>c,default:()=>p,frontMatter:()=>l,metadata:()=>t,toc:()=>d});const t=JSON.parse('{"id":"dynamic-data/query-examples/terms","title":"Term Queries","description":"Query WordPress taxonomy terms for category listings, tag clouds, and taxonomy-based navigation.","source":"@site/docs/dynamic-data/query-examples/terms.md","sourceDirName":"dynamic-data/query-examples","slug":"/dynamic-data/query-examples/terms","permalink":"/docs/dynamic-data/query-examples/terms","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"id":"terms","title":"Term Queries"},"sidebar":"docs","previous":{"title":"User Queries","permalink":"/docs/dynamic-data/query-examples/users"},"next":{"title":"Navigation Queries","permalink":"/docs/dynamic-data/query-examples/navigation"}}');var a=r(4848),s=r(8453),i=r(9489),o=r(7227);const l={id:"terms",title:"Term Queries"},c=void 0,u={},d=[{value:"What This Guide Covers",id:"what-this-guide-covers",level:2},{value:"Query Single Term",id:"query-single-term",level:2},{value:"Term ID vs Term Taxonomy ID",id:"term-id-vs-term-taxonomy-id",level:3},{value:"Complete Term Fields Reference",id:"complete-term-fields-reference",level:2},{value:"Basic Term Loop",id:"basic-term-loop",level:2},{value:"Custom Term Queries",id:"custom-term-queries",level:2},{value:"Query Arguments",id:"query-arguments",level:2},{value:"Complete Arguments Reference",id:"complete-arguments-reference",level:3},{value:"Basic Filtering",id:"basic-filtering",level:3},{value:"Term to Term Relationships",id:"term-to-term-relationships",level:2},{value:"Content Relationships",id:"content-relationships",level:2},{value:"Pagination",id:"pagination",level:2},{value:"Performance Tips",id:"performance-tips",level:2},{value:"Common Use Cases",id:"common-use-cases",level:2}];function m(e){const n={code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.p,{children:"Query WordPress taxonomy terms for category listings, tag clouds, and taxonomy-based navigation."}),"\n",(0,a.jsx)(n.h2,{id:"what-this-guide-covers",children:"What This Guide Covers"}),"\n",(0,a.jsx)(n.p,{children:"Terms are WordPress taxonomy data - categories, tags, and custom taxonomies that organize your content. This guide shows you how to query WordPress terms using Builderius GraphQL for any taxonomy scenario."}),"\n",(0,a.jsx)(n.p,{children:"You'll learn how to:"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsx)(n.li,{children:"Get current term data for archive templates"}),"\n",(0,a.jsx)(n.li,{children:"Query multiple terms for category listings and tag clouds"}),"\n",(0,a.jsx)(n.li,{children:"Filter terms by taxonomy, post counts, and custom criteria"}),"\n",(0,a.jsx)(n.li,{children:"Access custom term fields from ACF and MetaBox"}),"\n",(0,a.jsx)(n.li,{children:"Build taxonomy-based navigation and filtering"}),"\n",(0,a.jsx)(n.li,{children:"Handle term pagination and hierarchical relationships"}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"query-single-term",children:"Query Single Term"}),"\n",(0,a.jsxs)(i.A,{groupId:"terms-quick-start",defaultValue:"current",values:[{label:"Current Term",value:"current"},{label:"Specific Term",value:"specific"}],children:[(0,a.jsxs)(o.A,{value:"current",children:[(0,a.jsx)(n.p,{children:"Get the term you're currently viewing (on category/tag archives):"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:"{\n  archive {\n    term {\n      term_id\n      name\n      slug\n      description\n      count\n    }\n  }\n}\n"})})]}),(0,a.jsxs)(o.A,{value:"specific",children:[(0,a.jsx)(n.p,{children:"Get a term by ID, name, or slug:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  # Query by term ID (default identifier)\n  term(identifier: "term_id", value: 123, taxonomy: "category") {     # Int - Term ID number\n    name\n    slug\n    description\n  }\n  \n  # Query by term taxonomy ID\n  term(identifier: "term_taxonomy_id", value: 456, taxonomy: "category") {     # Int - Term taxonomy ID\n    name\n    slug\n    description\n  }\n  \n  # Query by term slug\n  term(identifier: "slug", value: "news", taxonomy: "category") {     # String - Term slug\n    name\n    slug\n    description\n  }\n  \n  # Query by term name\n  term(identifier: "name", value: "News", taxonomy: "category") {     # String - Term name\n    name\n    slug\n    description\n  }\n}\n'})})]})]}),"\n",(0,a.jsx)(n.h3,{id:"term-id-vs-term-taxonomy-id",children:"Term ID vs Term Taxonomy ID"}),"\n",(0,a.jsxs)(i.A,{groupId:"term-id-explanation",defaultValue:"normal",values:[{label:"Normal Use",value:"normal"},{label:"Rare Case",value:"rare"},{label:"When Taxonomy ID Matters",value:"when-needed"}],children:[(0,a.jsxs)(o.A,{value:"normal",children:[(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.strong,{children:"Normal WordPress Behavior (Separate Terms):"}),"\nWhen you create terms through wp-admin, each taxonomy gets its own separate terms (php code serves as explanation):"]}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"// Create \"News\" as category - gets term_id = 5, term_taxonomy_id = 10\nwp_insert_term('News', 'category');\n\n// Create \"News\" as tag - gets term_id = 6, term_taxonomy_id = 11  \nwp_insert_term('News', 'post_tag');\n"})}),(0,a.jsxs)(n.p,{children:["In this normal case, ",(0,a.jsx)(n.code,{children:"term_id"})," and ",(0,a.jsx)(n.code,{children:"term_taxonomy_id"})," are functionally equivalent for querying."]})]}),(0,a.jsxs)(o.A,{value:"rare",children:[(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.strong,{children:"Rare Case (Shared Terms Across Taxonomies):"}),"\nYou can programmatically force the same term to exist in multiple taxonomies (php code serves as explanation):"]}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"// Create term in first taxonomy\n$term = wp_insert_term('News', 'category');\n$term_id = $term['term_id']; // Let's say this is 5\n\n// Force same term into second taxonomy\nwp_insert_term('News', 'post_tag', array(\n    'term_id' => $term_id  // Same term_id = 5\n));\n"})}),(0,a.jsx)(n.p,{children:"Now you have:"}),(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"term_id"})," = 5 (same for both taxonomies)"]}
1),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"term_taxonomy_id"})," = 10 (for category relationship)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"term_taxonomy_id"})," = 11 (for tag relationship)"]}),"\n"]})]}),(0,a.jsxs)(o.A,{value:"when-needed",children:[(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.strong,{children:"When term_taxonomy_id Matters:"}),"\nOnly in this rare shared-term scenario do you need ",(0,a.jsx)(n.code,{children:"term_taxonomy_id"})," for precision:"]}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'# Gets the tag version of term_id 5\nterm(identifier: "term_taxonomy_id", value: 11, taxonomy: "post_tag")\n\n# Gets the category version of term_id 5  \nterm(identifier: "term_taxonomy_id", value: 10, taxonomy: "category")\n'})}),(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.strong,{children:"Practical Usage:"}),"\nMost of the time, use ",(0,a.jsx)(n.code,{children:"term_id"})," or ",(0,a.jsx)(n.code,{children:"slug"}),". Use ",(0,a.jsx)(n.code,{children:"term_taxonomy_id"})," only when working with shared terms or when you have specific term_taxonomy_id values from database queries or API responses."]})]})]}),"\n",(0,a.jsx)(n.h2,{id:"complete-term-fields-reference",children:"Complete Term Fields Reference"}),"\n",(0,a.jsx)(n.p,{children:"Here's what's available when querying a term - all standard WordPress taxonomy fields plus custom field integrations:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  term {\n    # Basic Fields\n    term_id\n    name\n    slug\n    term_group\n    term_taxonomy_id\n    taxonomy\n    description\n    count\n    parent\n    \n    # Children Terms (Hierarchy)\n    children {\n      term_id\n      name\n      slug\n      count\n    }\n    \n    # Native WordPress Meta Fields\n    featured_color: meta_value(key: "_featured_color")\n    custom_icon: meta_value(key: "_custom_icon")\n    \n    # All Meta Fields (returns array)\n    meta {\n      key\n      value\n    }\n    \n    # ACF Fields\n    category_image: acf_value(name: "category_image")\n    featured_on_homepage: acf_value(name: "featured_on_homepage")\n    category_color: acf_value(name: "category_color")\n    description_extended: acf_value(name: "description_extended")\n    \n    # ACF Repeater Fields\n    featured_posts: acf_repeater_value(name: "featured_posts") {\n      post_id: acf_value(name: "post_id")\n      featured_order: acf_value(name: "featured_order")\n    }\n    \n    # MetaBox Fields (Term Level)\n    category_priority: metabox_value(field_id: "category_priority")\n    display_settings: metabox_value(field_id: "display_settings")\n  }\n}\n'})}),"\n",(0,a.jsx)(n.h2,{id:"basic-term-loop",children:"Basic Term Loop"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n      hide_empty: true\n      number: 10\n    }\n  ) {\n    terms {\n      term_id\n      name\n      slug\n      description\n      count\n    }\n  }\n}\n'})}),"\n",(0,a.jsx)(n.h2,{id:"custom-term-queries",children:"Custom Term Queries"}),"\n",(0,a.jsxs)(n.p,{children:["Custom term queries ",(0,a.jsx)("span",{class:"badge pro",children:"Pro feature"})," let you manually specify exactly what terms you want, with your own filtering and arguments. You have complete control over which terms to display and how they're organized."]}),"\n",(0,a.jsxs)(i.A,{groupId:"custom-term-queries",defaultValue:"categories",values:[{label:"Categories",value:"categories"},{label:"Tags",value:"tags"},{label:"Custom Taxonomy",value:"custom"}],children:[(0,a.jsxs)(o.A,{value:"categories",children:[(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.strong,{children:"Category listings"})," with post counts:"]}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n      hide_empty: true\n      number: 15\n      orderby: "name"\n      order: "ASC"\n    }\n  ) {\n    terms {\n      term_id\n      name\n      slug\n      description\n      count\n      parent\n    }\n    pagination {\n      links\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"tags",children:[(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.strong,{children:"Tag cloud"})," ordered by popularity:"]}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "post_tag"\n      hide_empty: true\n      number: 50\n      orderby: "count"\n      order: "DESC"\n    }\n  ) {\n    terms {\n      term_id\n      name\n      slug\n      count\n      # Calculate tag weight for cloud display\n      tag_weight: expression_result(\n        expression: "min(count / 5, 10)"\n      )\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"custom",children:[(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.strong,{children:"Product categories"})," with custom fields:"]}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "product_category"\n      hide_empty: true\n      number: 20\n      orderby: "name"\n      order: "ASC"\n    }\n  ) {\n    terms {\n      term_id\n      name\n      slug\n      description\n      count\n      category_image: acf_value(name: "category_image")\n      featured_on_homepage: acf_value(name: "featured_on_homepage")\n      category_color: acf_value(name: "category_color")\n    }\n    pagination {\n      links\n    }\n  }\n}\n'})})]})]}),"\n",(0,a.jsx)(n.h2,{id:"query-arguments",children:"Query Arguments"}),"\n",(0,a.jsx)(n.h3,{id:"complete-arguments-reference",children:"Complete Arguments Reference"}),"\n",(0,a.jsxs)(n.p,{children:["All arguments available for ",(0,a.jsx)(n.code,{children:"terms_query"})," shown in context:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      # Taxonomy\n      taxonomy: "category"         # String or Array of str
1ings - Taxonomy name (category, post_tag, or custom taxonomy)\n      \n      # Include/Exclude Terms\n      include: [1, 5, 12]          # Array - Include only these term IDs\n      exclude: [3, 7]              # Array - Exclude these term IDs\n      \n      # Filter Options\n      hide_empty: true             # Boolean - Hide terms with no posts (true, false)\n      object_ids: [10, 25, 30]     # Array - Filter terms by object/post IDs\n      name: ["News", "Updates"]    # Array - Filter by term names\n      slug: ["news", "updates"]    # Array - Filter by term slugs\n      \n      # Pagination & Limits\n      number: 20                   # Int - Number of terms to return\n      offset: 5                    # Int - Number of terms to skip from start\n      \n      # Ordering\n      orderby: "name"              # String - Sort field (name, slug, term_group, term_id, description, count)\n      order: "ASC"                 # String - Sort direction (ASC, DESC)\n    }\n  ) {\n    terms {\n      name\n      slug\n    }\n  }\n}\n'})}),"\n",(0,a.jsx)(n.h3,{id:"basic-filtering",children:"Basic Filtering"}),"\n",(0,a.jsxs)(i.A,{groupId:"basic-filtering",defaultValue:"taxonomy",values:[{label:"By Taxonomy",value:"taxonomy"},{label:"Show Empty",value:"hide-empty"},{label:"Ordering",value:"ordering"},{label:"Include/Exclude",value:"include-exclude"}],children:[(0,a.jsxs)(o.A,{value:"taxonomy",children:[(0,a.jsx)(n.p,{children:"Filter by specific taxonomy:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n    }\n  ) {\n    terms {\n      name\n      slug\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"hide-empty",children:[(0,a.jsx)(n.p,{children:"Show only terms with posts:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n      hide_empty: false\n    }\n  ) {\n    terms {\n      name\n      slug\n      count\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"ordering",children:[(0,a.jsx)(n.p,{children:"Control term order and sorting:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n      orderby: "count"             # name, slug, count, term_id\n      order: "DESC"                # DESC, ASC\n    }\n  ) {\n    terms {\n      name\n      count\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"include-exclude",children:[(0,a.jsx)(n.p,{children:"Include or exclude specific terms:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n      include: [1, 5, 12]          # Only these terms\n      exclude: [3, 7]              # Exclude these terms\n    }\n  ) {\n    terms {\n      name\n      slug\n    }\n  }\n}\n'})})]})]}),"\n",(0,a.jsx)(n.h2,{id:"term-to-term-relationships",children:"Term to Term Relationships"}),"\n",(0,a.jsx)(n.p,{children:"Navigate between related terms using hierarchical and sibling relationships."}),"\n",(0,a.jsxs)(i.A,{groupId:"term-relationships",defaultValue:"current-parent",values:[{label:"Current Term Parent",value:"current-parent"},{label:"Sibling Terms",value:"sibling-terms"},{label:"Current Term Children",value:"current-children"},{label:"Term Hierarchy",value:"hierarchy"},{label:"Recursive Hierarchy",value:"recursive"}],children:[(0,a.jsxs)(o.A,{value:"current-parent",children:[(0,a.jsx)(n.p,{children:"Get parent term of the current term:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  archive {\n    term {\n      name\n      parent @private                    # Get parent ID for conditionals\n      parent_data: terms_query(          # Fetch parent term details\n        arguments: {\n          taxonomy: "category"  \n          include: "{{parent}}"\n        }\n      ) @private {\n        terms {\n          term_id @private\n          name\n        }\n      }\n      parent_is: expression_result(\n        expression: "(parent > 0) ? parent_data.terms[0].name : null"  # Show parent name or null\
1n      )\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"sibling-terms",children:[(0,a.jsx)(n.p,{children:"Get terms that share the same parent:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  archive {\n    term {\n      parent @private\n      sibling_terms: terms_query(\n        arguments: {\n          taxonomy: "category"\n          parent: "{{parent}}"      # Terms with same parent\n          hide_empty: true\n        }\n      ) {\n        terms {\n          name\n          slug\n          count\n        }\n      }\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"current-children",children:[(0,a.jsx)(n.p,{children:"Get child terms of the current term:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  archive {\n    term {\n      term_id @private\n      name\n      description\n      child_categories: terms_query(\n        arguments: {\n          taxonomy: "category"\n          parent: "{{term_id}}"      # Child terms of current term\n          hide_empty: true\n          orderby: "name"\n          order: "ASC"\n        }\n      ) {\n        terms {\n          term_id\n          name\n          slug\n          count\n        }\n      }\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"hierarchy",children:[(0,a.jsx)(n.p,{children:"Build a complete nested term hierarchy:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n      parent: 0                      # Top-level terms only\n      hide_empty: true\n      orderby: "name"\n      order: "ASC"\n    }\n  ) {\n    terms {\n      term_id\n      name\n      slug\n      count\n      # Get child terms for each parent\n      children: terms_query(\n        arguments: {\n          taxonomy: "category"\n          parent: "{{term_id}}"      # Children of this term\n          hide_empty: true\n          orderby: "name"\n          order: "ASC"\n        }\n      ) {\n        terms {\n          term_id\n          name\n          slug\n          count\n        }\n      }\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"recursive",children:[(0,a.jsx)(n.p,{children:"Build complete term hierarchy with unlimited nesting levels:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n      parent: 0                      # Top-level terms only\n      hide_empty: true\n      orderby: "name"\n      order: "ASC"\n    }\n  ) {\n    terms {\n      term_id\n      name\n      slug\n      count\n      # Recursive children - gets all nested levels automatically\n      children @recursive {\n        term_id\n        name\n        slug\n        count\n        parent\n      }\n    }\n  }\n}\n'})})]})]}),"\n",(0,a.jsx)(n.h2,{id:"content-relationships",children:"Content Relationships"}),"\n",(0,a.jsx)(n.p,{children:"Connect terms with their associated posts and content."}),"\n",(0,a.jsxs)(i.A,{groupId:"content-relationships",defaultValue:"current-post-terms",values:[{label:"Current Post Terms",value:"current-post-terms"},{label:"Single Term Posts",value:"single-term-posts"},{label:"Terms With Posts",value:"terms-posts"}],children:[(0,a.jsxs)(o.A,{value:"current-post-terms",children:[(0,a.jsx)(n.p,{children:"Get terms for the current post:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  post {\n    ID @private\n    post_categories: terms_query(\n      arguments: {\n        taxonomy: "category"\n        object_ids: "{{ID}}"     # Terms assigned to current post\n      }\n    ) {\n      terms {\n        name\n        slug\n        count\n      }\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"single-term-posts",children:[(0,a.jsx)(n.p,{children:"Get posts assigned to a single and specific term:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  term(identifier: "slug", value: "news", taxonomy: "category") {\n    term_id @private\n    name\n    slug\n    description\n    count\n    term_posts: posts_query(\n      arguments: {\n        tax_query: {\n          array: [\n            {\n              taxonomy: "category"\n              field: "term_id"\n              terms: "{{term_id}}"\n              operator: "IN"\n            }\n          ]\n        }\n        posts_per_page: 10\n        orderby: "date"\n        order: "DESC"\n      }\n    ) {\n      posts {\n        post_title\n        post_excerpt\n        post_date\n        permalink\n      }\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"terms-posts",children:[(0,a.jsx)(n.p,{children:"Get posts assigned grouped by terms:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n      object_ids: [10, 25, 30]     # Terms used by these specific posts\n      hide_empty: true\n    }\n  ) {\n    terms {\n      name\n      slug\n      count\n      # Show posts within each term\n      posts_in_term: posts_query(\n        arguments: {\n          post__in: [10, 25, 30]    # Only the specific posts we\'re filtering by\n          tax_query: {\n            array: [\n              {\n                taxonomy: "category"\n                field: "term_id"\n                terms: "{{term_id}}"\n                operator: "IN"\n              }\n            ]\n          }\n        }\n      ) {\n        posts {\n          post_title\n          permalink\n        }\n      }\n    }\n  }\n}\n'})})]})]}),"\n",(0,a.jsx)(n.h2,{id:"pagination",children:"Pagination"}),"\n",(0,a.jsx)(n.p,{children:"Handle pagination for term listings with custom URL parameters."}),"\n",(0,a.jsxs)(i.A,{groupId:"pagination",defaultValue:"basic",values:[{label:"Basic Pagination",value:"basic"},{label:"Advanced Pagination",value:"advanced"}],children:[(0,a.jsxs)(o.A,{value:"basic",children:[(0,a.jsx)(n.p,{children:"Basic term pagination:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n      hide_empty: true\n      number: 20\n      orderby: "name"\n      order: "ASC"\n    }\n  ) {\n    terms {\n      name\n      slug\n      count\n    }\n    pagination(\n      arguments: {\n        pagination_url_param_name: "category_page"\n      }\n    ) {\n      links\n      current_page\n      total_pages\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"advanced",children:[(0,a.jsx)(n.p,{children:"Advanced pagination with offset control and formatted page info display:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "product_category"\n      hide_empty: true\n      number: 15\n      offset: 0                        # Starting point for pagination\n      orderby: "count"\n      order: "DESC"\n    }\n  ) {\n    terms {\n      name\n      slug\n      count\n      category_image: acf_value(name: "category_image")\n    }\n    pagination(\n      arguments: {\n        pagination_url_param_name: "categories_page"\n      }\n    ) {\n      current_page\n      total_pages\n      links\n      # Enhanced pagination info\n      page_info: expression_result(\n        expression: "current_page . \' of \' . total_pages . \' pages\'"\n      )\n    }\n  }\n}\n'})})]})]}),"\n",(0,a.jsx)(n.h2,{id:"performance-tips",children:"Performance Tips"}),"\n",(0,a.jsx)(n.p,{children:"Optimize your term queries for better performance by using these techniques."}),"\n",(0,a.jsxs)(i.A,{groupId:"performance-tips",defaultValue:"private",values:[{label:"Use @private Fields",value:"private"},{label:"Limit Data",value:"limit"},{label:"Efficient Ordering",value:"ordering"}],children:[(0,a.jsxs)(o.A,{value:"private",children:[(0,a.jsxs)(n.p,{children:["Use ",(0,a.jsx)(n.code,{children:"@private"})," to query data you need for variables but don't want in output:"]}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  archive {\n    term {\n      term_id @private                 # Hidden from output, available for {{term_id}}\n      name\n      parent_category: terms_query(\n        arguments: {\n          taxonomy: "category"\n          include: "{{parent}}"      # Uses private parent field\n        }\n      ) {\n        terms {\n          name\n          slug\n        }\n      }\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"limit",children:[(0,a.jsx)(n.p,{children:"Only fetch the fields and terms you actually need:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n      number: 15                       # Don\'t fetch more than needed\n      hide_empty: true                 # Only terms with posts\n      orderby: "name"\n      order: "ASC"\n    }\n  ) {\n    terms {\n      name                             # Only fields you\'ll use\n      slug\n      count\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"ordering",children:[(0,a.jsx)(n.p,{children:"Use efficient ordering methods:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n      orderby: "name"                  # Efficient: name, term_id, count\n      order: "ASC"\n      number: 20\n    }\n  ) {\n    terms {\n      name\n      slug\n    }\n  }\n}\n'})})]})]}),"\n",(0,a.jsx)(n.h2,{id:"common-use-cases",children:"Common Use Cases"}),"\n",(0,a.jsx)(n.p,{children:"Real-world examples of term queries you'll commonly need for category listings, tag clouds, and taxonomy navigation."}),"\n",(0,a.jsxs)(i.A,{groupId:"common-use-cases",defaultValue:"category-nav",values:[{label:"Category Navigation",value:"category-nav"},{label:"Tag Cloud",value:"tag-cloud"},{label:"Terms with Posts",value:"terms-posts"}],children:[(0,a.jsxs)(o.A,{value:"category-nav",children:[(0,a.jsx)(n.p,{children:"Category navigation with hierarchy and custom images:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "category"\n      parent: 0                        # Top-level categories only\n      hide_empty: true                 # Only categories with posts\n      orderby: "name"\n      order: "ASC"\n    }\n  ) {\n    terms {\n      term_id\n      name\n      slug\n      count\n      # ACF fields for navigation\n      category_image: acf_value(name: "category_image")\n      featured_on_nav: acf_value(name: "featured_on_nav")\n      nav_
1color: acf_value(name: "nav_color")\n      # Child categories\n      subcategories: terms_query(\n        arguments: {\n          taxonomy: "category"\n          parent: "{{term_id}}"        # Children of this category\n          hide_empty: true\n          number: 10\n          orderby: "name"\n          order: "ASC"\n        }\n      ) {\n        terms {\n          name\n          slug\n          count\n        }\n      }\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"tag-cloud",children:[(0,a.jsx)(n.p,{children:"Weighted tag cloud with size classes:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "post_tag"\n      hide_empty: true                 # Only tags with posts\n      number: 100                      # Large number for full cloud\n      orderby: "count"                 # Most popular first\n      order: "DESC"\n    }\n  ) {\n    terms {\n      name\n      slug\n      count\n      # Calculate tag weight for CSS sizing\n      tag_size_class: expression_result(\n        expression: "count <= 2 ? \'tag-small\' : (count <= 10 ? \'tag-medium\' : \'tag-large\')"\n      )\n      # Alternative numerical weight\n      tag_weight: expression_result(\n        expression: "min(max(count, 1), 10)"\n      )\n    }\n  }\n}\n'})})]}),(0,a.jsxs)(o.A,{value:"terms-posts",children:[(0,a.jsx)(n.p,{children:"Terms with their recent posts nested inside:"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-graphql",children:'{\n  terms_query(\n    arguments: {\n      taxonomy: "product_category"     # Product categories\n      hide_empty: true                 # Only categories with products\n      orderby: "name"\n      order: "ASC"\n    }\n  ) {\n    terms {\n      term_id\n      name\n      slug\n      description\n      count\n      # Custom fields for category display\n      category_image: acf_value(name: "category_image")\n      featured_on_homepage: acf_value(name: "featured_on_homepage")\n      # Recent products in this category\n      recent_products: posts_query(\n        arguments: {\n          post_type: "product"           # Custom post type\n          posts_per_page: 6              # 6 products per category\n          tax_query: {\n            array: [\n              {\n                taxonomy: "product_category"\n                field: "term_id"\n                terms: ["{{term_id}}"]   # Products in this category\n                operator: "IN"\n              }\n            ]\n          }\n          orderby: "date"\n          order: "DESC"\n        }\n      ) {\n        posts {\n          post_title\n          post_excerpt\n          permalink\n          featured_image {\n            file_url(size: THUMBNAIL)   # Small thumbnails for category display\n            alt_text\n          }\n          # Product custom fields\n          price: acf_value(name: "price")\n          sale_price: acf_value(name: "sale_price")\n        }\n      }\n    }\n  }\n}\n'})})]})]})]})}function p(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(m,{...e})}):m(e)}},7227:(e,n,r)=>{r.d(n,{A:()=>i});r(6540);var t=r(8215);const a={tabItem:"tabItem_Ymn6"};var s=r(4848);function i({children:e,hidden:n,className:r}){return(0,s.jsx)("div",{role:"tabpanel",className:(0,t.A)(a.tabItem,r),hidden:n,children:e})}},8453:(e,n,r)=>{r.d(n,{R:()=>i,x:()=>o});var t=r(6540);const a={},s=t.createContext(a);function i(e){const n=t.useContext(s);return t.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:i(e.components),t.createElement(s.Provider,{value:n},e.children)}},9489:(e,n,r)=>{r.d(n,{A:()=>q});var t=r(6540),a=r(8215),s=r(8630),i=r(4245),o=r(6347),l=r(6494),c=r(2814),u=r(5167),d=r(9900);function m(e){return t.Children.toArray(e).filter(e=>"\n"!==e).map(e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad <Tabs>
1 child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)})?.filter(Boolean)??[]}function p(e){const{values:n,children:r}=e;return(0,t.useMemo)(()=>{const e=n??function(e){return m(e).map(({props:{value:e,label:n,attributes:r,default:t}})=>({value:e,label:n,attributes:r,default:t}))}(r);return function(e){const n=(0,u.XI)(e,(e,n)=>e.value===n.value);if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map(e=>e.value).join(", ")}" found in <Tabs>. Every value needs to be unique.`)}(e),e},[n,r])}function g({value:e,tabValues:n}){return n.some(n=>n.value===e)}function h({queryString:e=!1,groupId:n}){const r=(0,o.W6)(),a=function({queryString:e=!1,groupId:n}){if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!n)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:e,groupId:n});return[(0,c.aZ)(a),(0,t.useCallback)(e=>{if(!a)return;const n=new URLSearchParams(r.location.search);n.set(a,e),r.replace({...r.location,search:n.toString()})},[a,r])]}function y(e){const{defaultValue:n,queryString:r=!1,groupId:a}=e,s=p(e),[i,o]=(0,t.useState)(()=>function({defaultValue:e,tabValues:n}){if(0===n.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(e){if(!g({value:e,tabValues:n}))throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${n.map(e=>e.value).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}const r=n.find(e=>e.default)??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:n,tabValues:s})),[c,u]=h({queryString:r,groupId:a}),[m,y]=function({groupId:e}){const n=function(e){return e?`docusaurus.tab.${e}`:null}(e),[r,a]=(0,d.Dv)(n);return[r,(0,t.useCallback)(e=>{n&&a.set(e)},[n,a])]}({groupId:a}),x=(()=>{const e=c??m;return g({value:e,tabValues:s})?e:null})();(0,l.A)(()=>{x&&o(x)},[x]);return{selectedValue:i,selectValue:(0,t.useCallback)(e=>{if(!g({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),y(e)},[u,y,s]),tabValues:s}}var x=r(1062);const _={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=r(4848);function f({className:e,block:n,selectedValue:r,selectValue:t,tabValues:s}){const o=[],{blockElementScrollPositionUntilNextRender:l}=(0,i.a_)(),c=e=>{const n=e.currentTarget,a=o.indexOf(n),i=s[a].value;i!==r&&(l(n),t(i))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const r=o.indexOf(e.currentTarget)+1;n=o[r]??o[0];break}case"ArrowLeft":{const r=o.indexOf(e.currentTarget)-1;n=o[r]??o[o.length-1];break}}n?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":n},e),children:s.map(({value:e,label:n,attributes:t})=>(0,v.jsx)("li",{role:"tab",tabIndex:r===e?0:-1,"aria-selected":r===e,ref:e=>{o.push(e)},onKeyDown:u,onClick:c,...t,className:(0,a.A)("tabs__item",_.tabItem,t?.className,{"tabs__item--active":r===e}),children:n??e},e))})}function j({lazy:e,children:n,selectedValue:r}){const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(e){const e=s.find(e=>e.props.value===r);return e?(0,t.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map((e,n)=>(0,t.cloneElement)(e,{key:n,hidden:e.props.value!==r}))})}function b(e){const n=y(e);return(0,v.jsxs)("div",{className:(0,a.A)(s.G.tabs.container,"tabs-container",_.tabList),
1children:[(0,v.jsx)(f,{...n,...e}),(0,v.jsx)(j,{...n,...e})]})}function q(e){const n=(0,x.A)();return(0,v.jsx)(b,{...e,children:m(e.children)},String(n))}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.