Title: Posts shortcode: IN, NOT_IN, AND
Last modified: August 30, 2016

---

# Posts shortcode: IN, NOT_IN, AND

 *  [epic_serj](https://wordpress.org/support/users/epic_serj/)
 * (@epic_serj)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/posts-shortcode-in-not_in-and/)
 * Hello! I can’t understand one thing about filter in posts shorcode.
    I need to
   show all posts that have both “tag_1” and “tag_2”. I choose tags, then choose
   taxonomy operator “AND”. [https://yadi.sk/i/XwGAGgTWkSDUp](https://yadi.sk/i/XwGAGgTWkSDUp)
   The result shortcode is: `[su_posts posts_per_page="-1" taxonomy="post_tag" tax_term
   ="568,158" tax_operator="2"]` But in fact it displays the posts with any of chosen
   tags (works like IN) I tried to change tax_operator to 1|0 (NOT_IN, IN) and it
   returned same result — same posts list with any tax_operator value. Either I 
   don’t get the meaning of NOT_IN, IN, AND (it’s possible 🙂 or this functions 
   doesn’t work.
 * [https://wordpress.org/plugins/shortcodes-ultimate/](https://wordpress.org/plugins/shortcodes-ultimate/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [bhofmann](https://wordpress.org/support/users/bhofmann/)
 * (@bhofmann)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/posts-shortcode-in-not_in-and/#post-6746637)
 * I found the same problem. Did you ever get this resolved?
 *  Thread Starter [epic_serj](https://wordpress.org/support/users/epic_serj/)
 * (@epic_serj)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/posts-shortcode-in-not_in-and/#post-6746638)
 * No, still haven’t.
    I also encountered another strange bug about su_post. If 
   I get the post that is sheduled for future via ID, the shortcode returns nothing
   even after the sheduled post is published. I can even get the post via other 
   calls (by tag, for example), but ID becomes unreachable.
 *  [ExEquoVD](https://wordpress.org/support/users/exequovd/)
 * (@exequovd)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/posts-shortcode-in-not_in-and/#post-6746645)
 * Hope someone has the answer soon. Have the same question/problem
 *  [Michael Kracke](https://wordpress.org/support/users/krack3/)
 * (@krack3)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/posts-shortcode-in-not_in-and/#post-6746649)
 * I have the same issue, here is the code that deals with the operators, I am working
   through this code to see if I can find a fix
 * // Code from ‘shortcodes.php’, lines 1265 – 1303
 *     ```
       // If taxonomy attributes, create a taxonomy query
       		if ( !empty( $taxonomy ) && !empty( $tax_term ) ) {
       			// Term string to array
       			$tax_term = explode( ',', $tax_term );
       			// Validate operator
       			if ( !in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) ) $tax_operator = 'IN';
       			$tax_args = array( 'tax_query' => array( array(
       						'taxonomy' => $taxonomy,
       						'field' => ( is_numeric( $tax_term[0] ) ) ? 'id' : 'slug',
       						'terms' => $tax_term,
       						'operator' => $tax_operator ) ) );
       			// Check for multiple taxonomy queries
       			$count = 2;
       			$more_tax_queries = false;
       			while ( isset( $original_atts['taxonomy_' . $count] ) && !empty( $original_atts['taxonomy_' . $count] ) &&
       				isset( $original_atts['tax_' . $count . '_term'] ) &&
       				!empty( $original_atts['tax_' . $count . '_term'] ) ) {
       				// Sanitize values
       				$more_tax_queries = true;
       				$taxonomy = sanitize_key( $original_atts['taxonomy_' . $count] );
       				$terms = explode( ', ', sanitize_text_field( $original_atts['tax_' . $count . '_term'] ) );
       				$tax_operator = isset( $original_atts['tax_' . $count . '_operator'] ) ? $original_atts[
       				'tax_' . $count . '_operator'] : 'IN';
       				$tax_operator = in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) ? $tax_operator : 'IN';
       				$tax_args['tax_query'][] = array( 'taxonomy' => $taxonomy,
       					'field' => 'slug',
       					'terms' => $terms,
       					'operator' => $tax_operator );
       				$count++;
       			}
       			if ( $more_tax_queries ):
       				$tax_relation = 'AND';
       			if ( isset( $original_atts['tax_relation'] ) &&
       				in_array( $original_atts['tax_relation'], array( 'AND', 'OR' ) )
       			) $tax_relation = $original_atts['tax_relation'];
       			$args['tax_query']['relation'] = $tax_relation;
       			endif;
       			$args = array_merge( $args, $tax_args );
       		}
       ```
   
 *  Thread Starter [epic_serj](https://wordpress.org/support/users/epic_serj/)
 * (@epic_serj)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/posts-shortcode-in-not_in-and/#post-6746653)
 * Hi, everyone!
    I contacted the developer. The bug is about generating the shorcode
   text and it will be fixed in future version. Temporary solution is to change 
   generated shortcode text. Just fix text `[su_posts posts_per_page="-1" taxonomy
   ="post_tag" tax_term="568,158" tax_operator="2"]` to `[su_posts posts_per_page
   ="-1" taxonomy="post_tag" tax_term="568,158" tax_operator="AND"]` and it should
   work.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Posts shortcode: IN, NOT_IN, AND’ is closed to new replies.

 * ![](https://ps.w.org/shortcodes-ultimate/assets/icon-256x256.gif?rev=2547563)
 * [Shortcodes Ultimate - Content Elements](https://wordpress.org/plugins/shortcodes-ultimate/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/shortcodes-ultimate/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/shortcodes-ultimate/)
 * [Active Topics](https://wordpress.org/support/plugin/shortcodes-ultimate/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/shortcodes-ultimate/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/shortcodes-ultimate/reviews/)

 * 5 replies
 * 4 participants
 * Last reply from: [epic_serj](https://wordpress.org/support/users/epic_serj/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/posts-shortcode-in-not_in-and/#post-6746653)
 * Status: not resolved