Sometimes you may want to know what a function outputs. Here is hopefully a good cheatsheat for you.
Table of contents
get_terms
Purpose: Get the term for a specific taxonomy (Developer page).
Output
- If term found, return an array of WP_Term object
- If term does not exist, return WP_Error object
Example use: Find top-level terms from a category terms list.
get_term_link
Purpose: Get the term permalink. (Developer page)
Output
- WP_Error object if not found
- A string of url if term found
Example use: print out the term links for each term found in category.
get_queried_object
Purpose: To retrieve the current queried object (e.g from the page load) (Developer page).
Output
- In a post page, it outputs WP_Post object
- In an archive page, it outputs WP_Term object
- In an author page, it outputs WP_User object
Post page:
Category archive page:
Author page:
Example use
Return the tag name in uppercase first letter in an archive page:
term_exists
Purpose: Determines whether a taxonomy term exists, (possibly to check under a parent term) (Developer page).
Output
- If success, output an array with ‘term_id‘ and ‘term_taxonomy_id‘.
- If fail, returns null.
Example use
wp_insert_term
Purpose: Add a new term to the database, possibly to choose ‘description’, ‘parent’, ‘slug’ or ‘alias_of’ (Developer page).
Output (example)
- If successful, output like below
- If fail, output a WP_Error instance
Example use
Set a term name under a parent term
wp_set_object_terms
Purpose: Create Term and Taxonomy Relationships. (Developer page).
Output
- If failed, output is a WP_Error.
- If success, output as an array of term ids
Example use: Set multiple tag terms for one post.
Leave a Reply