Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * Filter Widget Post query
- *
- * @param array $query_args
- * @param array $instance
- *
- */
- add_filter( 'streamtube/core/widget/posts/query_args', function( $query_args, $instance ){
- /**
- *
- * Holds the custom taxonomy slug(s), for instance: custom-taxonomy-slug or array( 'custom-taxonomy-slug' )
- *
- * @var string|array
- */
- $taxonomy = 'custom-taxonomy-slug';
- // Holds the widget ID
- $widget_id = 'posts-widget-9';
- // Holds relation
- $relation = 'AND'; // or OR
- if( array_key_exists( 'id', $instance ) && $instance['id'] == $widget_id ){
- if( $query_args['tax_query'] ){
- unset( $query_args['tax_query']['relation'] );
- if( is_string( $taxonomy ) ){
- $taxonomy = array( $taxonomy );
- }
- $tax_query = compact( 'relation' );
- for ( $i=0; $i < count( $query_args['tax_query'] ); $i++) {
- if( is_array( $query_args['tax_query'][$i] ) ){
- if( in_array( $query_args['tax_query'][$i]['taxonomy'], $taxonomy ) ){
- $tax_query[] = $query_args['tax_query'][$i];
- }
- }
- }
- }
- if( $tax_query ){
- $query_args = array_merge( $query_args, compact( 'tax_query' ) );
- }
- }
- return $query_args;
- }, 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement