get_terms: name parameter is double-escaped
-
Hi everybody.
I have a troubleshoot with searching terms by name (via get_terms) when term name is something like “L’elegia“.my get_terms call is:
$get_term_args = array('name'=>$term, 'hide_empty'=>false); $fount_cats = get_terms($taxonomy, $get_term_args);
its all ok with the most of terms, but I found that i cant get existing term “L’elegia”.
i’ve hecked the $wpdb->last_qeury content:
SELECT t.*, tt.* FROM swwp_terms AS t INNER JOIN swwp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('good_category') AND t.name IN ('L\\\'elegia') ORDER BY t.name ASC
As you can see, the name was double-escaped (‘L\\\’elegia’ instead of ‘L\’elegia’)
and that’s what i’ve found in includes/taxonomy.php at 1878:
if ( ! empty( $args['name'] ) ) { $names = (array) $args['name']; foreach ( $names as &$_name ) { $_name = sanitize_term_field( 'name', $_name, 0, reset( $taxonomies ), 'db' ); } $where .= " AND t.name IN ('" . implode( "', '", array_map( 'esc_sql', $names ) ) . "')"; }
As you see, each $name is escaped twice (by sanatize_term_field and by esc_sql). This is doesnt matters when it’s nothing to escape in term names, but in my case it causes an error.
So the question:
– is this bug of feature? is there some legal way or workaround to avoid this double-escaping?Thanks in advance.
- The topic ‘get_terms: name parameter is double-escaped’ is closed to new replies.