• 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
    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://ww.wp.xz.cn/plugins/shortcodes-ultimate/

Viewing 5 replies - 1 through 5 (of 5 total)
  • I found the same problem. Did you ever get this resolved?

    Thread Starter epic_serj

    (@epic_serj)

    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.

    Hope someone has the answer soon. Have the same question/problem

    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

    (@epic_serj)

    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.