get_term_by for multiple cats with same name
-
Is get_term_by actually a correct function ?
E.g.:
get_term_by('name','book','category')
works as long as you only have one category in there with the name book, but if you have \bla\book and \def\dof\book also, it will just be random which one it will output.
So instead of the get_term_by query:
$term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE $_field = %s", $value ) . " $tax_clause LIMIT 1" );
Maybe it should check if there are multiple returned then also return multiple in all cases, I think LIMIT 1 should be removed, otherwise you can never check if multiple exist.
$term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE $_field = %s", $value ) . " $tax_clause " );
So you cant use ‘name’, otherwise you would need to do something like:
$categorychildren = get_term_children(config::getRootTermId(), 'category'); foreach($categorychildren as $wp_category_id) { $cat_object = get_term($wp_category_id, 'category'); if ($cat_object->name == $whatwelookfor) { // .. do the rest } }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘get_term_by for multiple cats with same name’ is closed to new replies.