Title: Shortcode array in array (custom taxonomy)
Last modified: August 20, 2016

---

# Shortcode array in array (custom taxonomy)

 *  [mwellis](https://wordpress.org/support/users/mwellis/)
 * (@mwellis)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/shortcode-array-in-array-custom-taxonomy/)
 * I am using a widget, U more recent posts. Seems to work with custom taxonomies
   when you input the correct data into it in a widget form, but the suggested shortcode
   doesn’t work (and I am trying to insert it into a post).
 * He suggests including the following query in the shortcode;
 * `tax_query="taxonomy=category&terms=14,17"`
 * so I have tried….
 * `[u_more_recent_posts id="hue-recent-posts" tax_query="taxonomy=destinations&
   terms=174" post_type="post"]`
 * where destinations is the name of my custom taxonomy and 174 is the id of the
   posts I want to display.
 * I am sure, I just need to alter the shortcode slightly for it to work, but have
   been trying for hours and can’t work it out!! Any help would be ENORMOUSLY appreciated!!
 * I think the relevant code in the plugin are;
 *     ```
       if( !empty($opts['post_type']) ) {
       		$query_args['post_type'] = $opts['post_type'];
   
       		if( !empty($opts['tax_query']) AND isset($opts['tax_query'][$opts['post_type']]) ) {
       			$tax_query = $opts['tax_query'][$opts['post_type']];
   
       			if( !empty($tax_query['taxonomy']) AND !empty($tax_query['terms']) ){
       				$tax_query['terms'] = explode(',', preg_replace('/\s*/', '', $tax_query['terms']));
       				$_tax_query = array(
       					'taxonomy' => $tax_query['taxonomy'],
       					'terms' => $tax_query['terms'],
       					'field' => 'id',
       				);
       				$operator = '';
       				switch($tax_query['operate']){
       					case 'include': $operator = 'IN'; break;
       					case 'exclude': $operator = 'NOT IN'; break;
       					case 'and': $operator = 'AND'; break;
       				}
       				if( !empty($operator) )
       					$_tax_query['operator'] = $operator;
   
       				$query_args['tax_query'] = array($_tax_query);
       			}
       		}
       	}
       ```
   
 * and this bit…..
 *     ```
       if( isset($atts['tax_query']) ){
       		$opts['tax_query'] = array($opts['post_type'] => wp_parse_args(preg_replace('/&/', '&', $atts['tax_query'])));
       	}
       ```
   
 * Thanks very much in advance for any help, I am completely stuck!!

Viewing 1 replies (of 1 total)

 *  [cdaniel9](https://wordpress.org/support/users/cdaniel9/)
 * (@cdaniel9)
 * [12 years, 12 months ago](https://wordpress.org/support/topic/shortcode-array-in-array-custom-taxonomy/#post-2884756)
 * Think this is a little late to be helpful Nevertheless had the same problem, 
   hacked the code to see what exactly was being passed in and figured it out.
 * Replace the literal & with the html code `&`amp;
 * [u_more_recent_posts id=”hue-recent-posts” tax_query=”taxonomy=destinations`&`
   amp;terms=174″ post_type=”post”]

Viewing 1 replies (of 1 total)

The topic ‘Shortcode array in array (custom taxonomy)’ is closed to new replies.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [custom taxonomy](https://wordpress.org/support/topic-tag/custom-taxonomy/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [cdaniel9](https://wordpress.org/support/users/cdaniel9/)
 * Last activity: [12 years, 12 months ago](https://wordpress.org/support/topic/shortcode-array-in-array-custom-taxonomy/#post-2884756)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
