From what I can read in your comments (and your follow up question), you are trying to intercept the WHERE
clause of your query. The name__like
argument you mentioned in your other question won’t work for what you are trying to achieve. The clause is built this way by get_terms()
(the underlying function of get_tags()
):
if ( ! empty( $args['name__like'] ) ) {
$where .= $wpdb->prepare( " AND t.name LIKE %s", '%' . $wpdb->esc_like( $args['name__like'] ) . '%' );
}
As you can see, it’s %YOURTERM%
, so it matches not only from the beginning, but from the end as well. To make it short: This is not what you want.
After reading source, it’s simple: You need to rebuild the complete query. There’s a filter for that:
$clauses = apply_filters( 'terms_clauses', compact( $pieces ), $taxonomies, $args );
Simply add a callback to it and modify your query to $wpdb->esc_like( 'term' ).'%'
:
add_filter( 'terms_clauses', function( $sql, $taxonomies, $args )
{
// rebuild your query here
return $sql;
}, PHP_INT_MAX -1, 3 );