Skip to main content

wp term get

Overview

Inspect a single taxonomy term — ID, slug, description, parent, count, and more. Use this before updating, assigning to posts, or scripting conditional logic on terms.

What It Does

wp term get calls get_term_by() and returns the term object fields. You can reference the term by its ID or slug.

Syntax

wp term get <taxonomy> <term> [OPTIONS]

TERM can be a term ID or slug.

Arguments & Options

FlagDescription
--by=FIELDIdentifier type: term_id (default) or slug
--field=FIELDReturn one field value
--fields=FIELDSReturn specific fields
--format=FORMATtable, json, yaml, csv

Basic Usage

Get by slug

wp term get category technology --by=slug

Get by ID

wp term get category 12

Get a single field

wp term get category technology --by=slug --field=term_id

Real-World Scenarios

Get term ID for scripting

TERM_ID=$(wp term get category technology --by=slug --field=term_id)
wp post term add 42 category $TERM_ID

Check a term's post count

COUNT=$(wp term get post_tag wordpress --by=slug --field=count)
echo "Posts tagged 'wordpress': $COUNT"

Quick Reference

wp term get <taxonomy> <id>                       # By ID
wp term get <taxonomy> <slug> --by=slug # By slug
wp term get <taxonomy> <term> --field=term_id # ID only
wp term get <taxonomy> <term> --format=json # JSON

Next Steps