Forums

Shortcode array in array (custom taxonomy) (1 post)

  1. mwellis
    Member
    Posted 10 months ago #

    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!!

Reply

You must log in to post.

About this Topic