Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 736

In WordPress, terms are itens set to a taxonomy, i.e. when you create new categories or tags you create new terms.

1 vote

WordPress Term for Custom List

These are custom post types. You create them by registering them with WordPress on page loads. You do this by calling register_post_type either in: Your themes functions.php On the init hook ( I ma …
Tom J Nowell's user avatar
  • 60.6k
0 votes

Custom Template for one Taxonomy Term

That's easy, instead of trying to change which template gets loaded, load the single-grants.php template, then use get_template_part inside it, and pass different values based on the terms the post has …
Tom J Nowell's user avatar
  • 60.6k
14 votes
Accepted

When to / not to use wp_get_post_terms vs get_the_terms?

$terms = get_the_terms( $post_id, 'cat' ); Now there is a temptation here to go down again to wp_get_object_terms but this is uncached, and so you'll see performance and scaling issues. …
Tom J Nowell's user avatar
  • 60.6k
2 votes
Accepted

get_term does not return the term

I am using my own taxonomy which has in the table terms corresponding row with a term. I need to get the term by term_id using get_term(141) but i get error invalid_taxonomy. … Using WP CLI to do it, you can execute a system command from PHP or another language to create terms e.g. wp term create category Apple --description="A type of fruit" …
Tom J Nowell's user avatar
  • 60.6k
0 votes

get_terms not working when child_of is used

stuff, use the dedicated function instead: clean_taxonomy_cache( 'department' ); Or if you have WP CLI: wp cache flush Other options include: delete_option( 'department_children' ); Creating/deleting terms
Tom J Nowell's user avatar
  • 60.6k
0 votes

taxonomy terms are not populating select tag options

So lets update the code with some escaping so that it's secure: $terms = get_terms( 'department' ); if ( ! empty( $terms ) && ! … We can also simplify the code to make it easier to read: $terms = get_terms( 'department' ); if ( ! empty( $terms ) && ! …
Tom J Nowell's user avatar
  • 60.6k
0 votes

Display x number of terms and exclude hidden

Googling get_terms gives the WP developer hub page for get_terms as the first result, for which the first example is this: $terms = get_terms( 'post_tag', array( 'hide_empty' => false, ) ); Using … this as a basis we get: $args = array( 'taxonomy' => 'product_cat', 'number' => 5, 'orderby' => 'name', 'parent' => 11, 'hide_empty' => true, ); $terms = get_terms( $args ); …
Tom J Nowell's user avatar
  • 60.6k
0 votes

How to show only tagged CPT categories / taxonomies for a custom post type?

For example, if we want to grab all terms in a product taxonomy for a post we might do: $product_terms = wp_get_object_terms( $post->ID, 'product' ); if ( ! empty( $product_terms ) ) { if ( ! …
Tom J Nowell's user avatar
  • 60.6k
1 vote
Accepted

How add default term meta to prevent an error?

You don't, or at least not in the way you expect. If the code in the question worked as expected, it would still be committing a mortal performance sin, database writes on the frontend. So lets take …
Tom J Nowell's user avatar
  • 60.6k
0 votes

How can I show links for custom posts group by taxonomy current term and sub-term?

I believe you're missing 3 important pieces of information: terms that have no parent have a parent ID of 0 you can ignore get_term_children, just use the parent parameter of get_terms for this to work …
Tom J Nowell's user avatar
  • 60.6k
0 votes
Accepted

update_term_meta not working

A terms slug is not stored as meta/custom fields, and it's definitely not post meta, so update_term_meta and update_post_meta are innapropriate and can never be used to achieve your goal. …
Tom J Nowell's user avatar
  • 60.6k
1 vote

wp set object terms vs wp set post terms

As for why there are 2 separate functions, it may be useful to know that not all terms and taxonomies are for posts. … It is possible to create taxonomies and terms for other objects too, such as user taxonomies, comment taxonomies, etc. Much like how you can have user meta, comment meta etc. …
Tom J Nowell's user avatar
  • 60.6k
4 votes

Retrieve taxonomies from arbitrary site

how can I retrieve all taxonomy terms for a post in an arbitrary site programmatically? … Retrieving all Terms We can retrieve all terms in a site, then loop over them to identify the taxonomy fields: $query = new WP_Term_Query([]); $terms = $query->get_terms(); $taxonomies = wp_list_pluck( …
Tom J Nowell's user avatar
  • 60.6k
2 votes
Accepted

How to write sql query to get the posts from a custom taxonomy term name

could do something like the following: $args = array( 'post_type' => 'dealers' 'tax_query' => array( array( 'taxonomy' => 'state', 'field' => 'slug', 'terms … ' => array('bob','angela','john','smith','jan','doe','etc...') ) ) ); $query = new WP_Query( $args ); Note the multiple state terms being queried, not the single specific one. …
Tom J Nowell's user avatar
  • 60.6k
4 votes
Accepted

Taxonomy order exception for specific term

Here is the example of get_terms in the Codex: $terms = get_terms("my_taxonomy"); $count = count($terms); if ( $count > 0 ){ echo "<ul>"; foreach ( $terms as $term ) { echo "<li>" . … $terms = get_terms("my_taxonomy"); $count = count($terms); if ( $count > 0 ){ echo "<ul>"; $other_term = null; foreach ( $terms as $term ) { if($term->name == 'other'){ …
Tom J Nowell's user avatar
  • 60.6k

15 30 50 per page