by( $operation, $taxonomy, $terms ); // This will only build the query not execute it. $built_query = $repo->build_query(); if ( ! empty( $built_query->query_vars['tax_query'] ) ) { $tax_query = $built_query->query_vars['tax_query']; } return $tax_query; } /** * Transform all Term IDs and Slugs into IDs of existing terms in a given taxonomy. * * @since 4.13.0 * * @param string|int|array $terms Terms to be cleaned up. * @param string $taxonomy Which taxonomy we are querying for. * * @return array List of IDs of terms. */ public static function normalize_to_term_ids( $terms, $taxonomy ) { if ( empty( $terms ) ) { return $terms; } /** * Allow filtering of the needle for splitting terms, by default it will be a comma. * * @since 4.13.0 * * @param string $needle Defaults to a comma. Which character that we will split terms by. * @param string|array $terms Terms string that we will split by the needle filtered. * @param string $taxonomy Which taxonomy this will be for. */ $needle = apply_filters( 'tribe_normalize_to_term_ids_needle', ',', $terms, $taxonomy ); if ( is_string( $terms ) && false !== strpos( $terms, $needle ) ) { $terms = array_map( 'trim', explode( $needle, $terms ) ); } $terms = array_map( static function ( $param ) use ( $taxonomy ) { $param = preg_replace( '/^#/', '', $param ); $term_by = is_numeric( $param ) ? 'ID' : 'slug'; $term = get_term_by( $term_by, $param, $taxonomy ); if ( ! $term instanceof \WP_Term ) { return false; } return $term->term_id; }, (array) $terms ); $terms = array_filter( $terms ); $terms = array_unique( $terms ); return $terms; } }