• Hello everyone,
    I would like to include only selected taxonomies ID in my loop (via shortcode), but can’t achieve it. I do not know what I’m doing wrong.

    This is my shortcode code (not working):

    add_shortcode( 'myshrt', 'my_shortcode' );
    function my_shortcode( $atts ) {
    
    extract(shortcode_atts(array(
          'posts' => -1,
          'include' => '',
       ), $atts));
    
    $args = array(
    	'post_type' => 'my_custom_post_type',
    	'showposts' => $posts,
    	'orderby' => 'date',
    	'order' => 'DESC',
                  'tax_query' => array(
                            array(
                           'taxonomy' => 'my_custom_tax',
                            'field' => 'id',
    	                'terms' => array( $include )
                             )
                  ),
    
    );
    $mynewquery = new WP_Query( $args );
    
    ?>
    
    <?php if ( $mynewquery->have_posts() ) : while ( $mynewquery->have_posts() ) : $mynewquery->the_post(); ?>
    
    <h2><?php the_title(); ?><h2/>
    <?php endwhile; else: ?>
    <?php endif; ?>
    <?php wp_reset_query(); ?>
    
    }

    I put shortcode like this:
    [myshrt posts="5" include="40,50"]

    But without effect.
    Can anybody help ?

  • The topic ‘Include selected taxonomy ID in loop (from shortcode)’ is closed to new replies.