WordPress.org

Ready to get started?Download WordPress

Forums

How to display events in CPT from only one cetegory (1 post)

  1. sparklogix
    Member
    Posted 1 year ago #

    I've got a shortcode and I'm trying to get it to display the events from a CPT from only one category in the CPT, not all of them. This is what my current code looks like:

    function sc_kgClassSidebar($atts) {
    	extract(shortcode_atts(array(
    				'items'=>'4'
    				),$atts));		   
    
    		$event = new WP_Query(array( 'post_type' => 'classes', 'posts_per_page' => $items ,'orderby'=>'meta_value', 'meta_key' => 'Start Date', 'order'=>'DESC', 'taxonomy' => 'data-warehouse-lifecycle-in-depth', 'field' => 'slug'));
    
    		$options = get_option('kgTheme_site_cfg');
    		$classpage = $options['sched_page'];
    		$markup = '';
    
    if($event->have_posts()) {
    	while($event->have_posts()) {
    			$event->the_post();
    		$custom_fields = get_post_custom($event->ID);
    
    			 if ( $custom_fields['Savings'][0]!='' ) {
    			$markup .= '<div class="reg-item">'."\n";
    			$markup .= '<a class="reg-btn" target="_blank" href="'.$custom_fields['Register URL'][0].'" title="Register">Register</a>'."\n";
    			$markup .= '<div class="reg-cnt">'."\n";
    			$markup .= '<h3><a href="'.get_permalink($event->ID).'" title="'.get_the_title($event->ID).'" >'.get_the_title($event->ID).'</a></h3>'."\n";
    			$markup .= '<p><span class="details">'.$custom_fields['Dates'][0].', '.$custom_fields['Location'][0].' </span> </p>'."\n";
    			$markup .= '<p><span class="save">Save '.$custom_fields['Savings'][0].' if you register by '.$custom_fields['Deadline'][0].'</span></p>'."\n";
    			$markup .= '</div>'."\n";
    			$markup .= '</div>'."\n\n";
    			 } else {
    			$markup .= '<div class="reg-item">'."\n";
    			$markup .= '<a class="reg-btn" target="_blank" href="'.$custom_fields['Register URL'][0].'" title="Register">Register</a>'."\n";
    			$markup .= '<div class="reg-cnt">'."\n";
    			$markup .= '<h3><a href="'.get_permalink($event->ID).'" title="'.get_the_title($event->ID).'" >'.get_the_title($event->ID).'</a></h3>'."\n";
    			$markup .= '<p><span class="details">'.$custom_fields['Dates'][0].', '.$custom_fields['Location'][0].' </span> </p>'."\n";
    			//$markup .= '<p><span class="save-hidden">&nbsp;</span></p>'."\n";
    			$markup .= '</div>'."\n";
    			$markup .= '</div>'."\n\n";
    			 }
    	}
    }
    wp_reset_postdata();
    
    	if(($classpage!='') || ($classpage == 'not-set')) {
    		$markup .= ''."\n\n";
    	}
    
    	return $markup;
    }
    add_shortcode('kgClassSidebar','sc_kgClassSidebar');

    I didn't originally create this and am not to familiar with this stuff. I've looked through this info, but can't seem to get it to work: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

    What am I doing wrong? It's still returning ALL posts (regardless of category) in the shortcode. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic