Skip to content

Instantly share code, notes, and snippets.

@joehoyle
Created February 17, 2015 18:30
Show Gist options
  • Select an option

  • Save joehoyle/d524e91ae7754fa0680a to your computer and use it in GitHub Desktop.

Select an option

Save joehoyle/d524e91ae7754fa0680a to your computer and use it in GitHub Desktop.
function hm_add_term_meta_query_support( $pieces, $taxonomies, $args ) {
if ( empty( $args['meta_query'] ) ) {
return $pieces;
}
$meta_query = new WP_Meta_Query( $args['meta_query'] );
$sql = $meta_query->get_sql( 'term', 't', 'term_id' );
if ( ! $sql ) {
return $pieces;
}
$pieces['join'] .= $sql['join'];
$pieces['where'] .= $sql['where'];
return $pieces;
}
@joehoyle

Copy link
Copy Markdown
Author

Usage:

get_terms( 'ticker', array( 
    'meta_query' => array(
      'key' => 'is_etf',
      'value' => '1'
    )
) );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment