Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?

Unfortunately, this is not possible, at least not safe. The function wp_insert_term( $term, $taxonomy, $args = array() ) that handles the creation of taxonomies provides a few filters and hooks, but the only one before the creation of the term in the database is $term = apply_filters( ‘pre_insert_term’, $term, $taxonomy ); As you can see, … Read more

get_term and get_term_by return null or false, even though term exists

To use get_term_by we need the term object before it gets deleted. Therefore, we should use the action hook delete_term_taxonomy that runs before the term is deleted. Now, we can go ahead and perform some tasks such as deleting all the postmeta related to the term being deleted. The code is: add_action( ‘delete_term_taxonomy’, function($tt_id) { … Read more

Multiple portfolios and single item in two of them (ideas?)

One simple option would be to add a parameter to the query string of the portfolio item (i.e. yousite.com/portfolio-item/?backto=portfolio-3), then on the item page modify the ‘back’ link with JavaScript: if the backto parameter exists then change the link to point to the portfolio specified in it. Here’s some untested starter code. On the portfolio … Read more

Conditional Statement custom post type category

is_category() does not work on custom taxonomy archive pages. The correct conditional tag here is is_tax() which takes the name of the taxonomy as first parameter and a string|int|array of term name/s, slug/s or ID/s as second parameter. So your whole conditional statement can look something like : if ( is_tax( ‘my_taxonomy’, ‘slug-name-of-the-term’) ) { … Read more

Hide posts having children terms when display posts by category in edit.php

By default when you run a query for a hierarchical taxonomy term, WordPress also returns post from its children. This happen on backend and on frontend as well. ‘tax_query’ argument has an argument ‘include_children’ that was introduced for the scope, from Codex: include_children (boolean) Whether or not to include children for hierarchical taxonomies. Defaults to … Read more

Enable the admin to sort custom taxonomy

Thanks to this great tutorial, I just found the answer myself. WordPress offers the action hooks sb_reference_category_add_form_fields, sb_reference_category_edit_form_fields, create_sb_reference_category and edited_sb_reference_category (these are named after the custom taxonomy, in my case sb_reference_category). With these hooks, it is easy as pie to add and save a custom field to the taxonomy.

Custom Taxonomy Template Error: Catchable fatal error: Object of class WP_Error could not be converted to string

Well, you echo an object. Never just echo stuff if you are not sure what you get in return. Take a look at the function: The error itself is quite clear: function get_term_link( $term, $taxonomy = ”) { global $wp_rewrite; if ( !is_object($term) ) { if ( is_int($term) ) { $term = get_term($term, $taxonomy); } … Read more