Get category ID after wp_insert_term
It should be a key of term_id, so echo out $cat_id[‘term_id’] and you should get the new terms ID.
It should be a key of term_id, so echo out $cat_id[‘term_id’] and you should get the new terms ID.
There are two problems that have thwarted your check: $term = get_queried_object()->term_id; if ( $term->parent == ‘tradeshow’ ) { Starting with: $term = get_queried_object()->term_id; Here $term contains the ID of a term, not a term object. Lets assume this is term number 5, the result is: $term = 5; if ( $term->parent == ‘tradeshow’ ) … Read more
We had the same issue in one of our projects and we find the solution here This other doesn’t work in our case, but maybe is a second option for you.
How to get_terms() only of terms matching an ACF meta value?
Ad slowing down) Lame answer: depends on your server and stuff. Ad possible bug) wp_count_terms(); is a level “above” get_terms(); and therefore has values like ‘hide_empty’ and ‘fields’ already set. I’d say: diff your $args against those predefinied by wp_count_term();. The later function does nothing than calling the get_terms() at it’s end.
For a menu object $item: $item->object stores the object the menu item refers to, e.g. ‘post’, ‘page’, ‘my-cpt’, or ‘my-taxonomy’ (the post type name, or the taxonomy name) $item->type stores what ‘type’ of object is it, either: ‘post_type’ or ‘taxonomy’. For custom links, these are both custom
first you should set the taxnomy in custom post type you have just set only for post title post content post comments you did not set for custom taxnomy $post = array(‘tax_input’ => [ array( <taxonomy> => <array | string> ) ] // For custom taxonomies. Default empty. ‘page_template’ => [ <string> ] // Requires … Read more
As noted in the OP’s comments, some non-ASCII characters may not be supported in term names under certain conditions. To replace all suspect characters with an underscore, use the following code: $categoryname = preg_replace(‘/[^a-z0-9]/i’, ‘_’, strtolower($categoryname)); wp_insert_term($categoryname, “department”); To replace all suspect characters with a dash, use the following code: $categoryname = preg_replace(‘/[^a-z0-9]/i’, ‘-‘, strtolower($categoryname)); … Read more
I’m afraid there won’t be a nice way to do this… One way will be to: get all the found posts, for every one of them get its terms, count the terms. But it won’t be very efficient and I wouldn’t recommend this way of doing it. On the other hand there is an efficient, … Read more
This code display all posts of all categories of genre taxonomy for custom post type book. Now, For different custom post type (author, product ) you have to change Custom Post Type Name inside $arg of WP_Query(). You will get term link using get_term_link($catterm) function or you can use also get_the_term_list(). $args = array( ‘number’ … Read more