Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function filter_by_terms( $post_ids, $term_ids )
- {
- global $wpdb;
- // ===============================================
- // = Sanitize provided IDs against SQL injection =
- // ===============================================
- if( ! is_array( $post_ids ) )
- $post_ids = explode( ',', $post_ids );
- foreach( $post_ids as &$post_id ) {
- $post_id = intval( $post_id );
- }
- $post_ids = join( ',', $post_ids );
- if( ! is_array( $term_ids ) )
- $term_ids = explode( ',', $term_ids );
- foreach( $term_ids as &$term_id ) {
- $term_id = intval( $term_id );
- }
- $eventTaxonomy = $wpdb->get_results( "SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE taxonomy like 'events%'", OBJECT_K );
- foreach ($term_ids as $termID) {
- $taxoIDs[$eventTaxonomy[$termID]->taxonomy][$termID] = $termID;
- }
- $args['post_type'] = 'ai1ec_event';
- $args['post_status'] = 'published';
- $args['posts_per_page'] = 999;
- $args['tax_query']['relation'] = 'AND';
- if ( !empty($taxoIDs['events_tags']) ) {
- $args['tax_query'][0]['taxonomy'] = 'events_tags';
- $args['tax_query'][0]['field'] = 'id';
- $args['tax_query'][0]['terms'] = $taxoIDs['events_tags'];
- $args['tax_query'][0]['operator'] = 'AND';
- }
- if ( !empty($taxoIDs['events_categories']) ) {
- $args['tax_query'][1]['taxonomy'] = 'events_categories';
- $args['tax_query'][1]['field'] = 'id';
- $args['tax_query'][1]['terms'] = $taxoIDs['events_categories'];
- $args['tax_query'][1]['operator'] = 'IN';
- }
- $events = new WP_Query( $args );
- return $wpdb->get_col( $events->request );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement