Support

Home Forums Event Espresso Premium Help with Template PHP Code

Help with Template PHP Code

Posted: September 24, 2014 at 7:53 am

Viewing 3 reply threads


Christopher David

September 24, 2014 at 7:53 am

I have created a custom List template but I need to restrict the return to only 4 different category types. Here is my code

$atts = array(
‘title’ => NULL,
‘limit’ => 100,
‘css_class’ => NULL,
‘show_expired’ => FALSE,
‘month’ => NULL,
‘order_by’ => ‘start_date’,
‘sort’ => ‘ASC’,
);
// run the query
global $wp_query;
$wp_query = new EE_Event_List_Query( $atts );

I know I need to add a line but this does not seem to work

‘category_slug’ => ‘maestro-series, family-series, mansion-series, cab-series’

Any help would be great. Thanks so much


Dean

September 25, 2014 at 5:59 am

Hi,

category_slug is not a valid WP_Query parameter, us category_name (which actually uses the slug).

Please see here: http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters


Christopher David

September 26, 2014 at 8:04 am

I am sorry but the reference code you provided does not work. Adding this line of code in fact returns the correct single category and works fine for a single category.

‘category_slug’ => ‘maestro-series’,

Adding this does not return any results

‘cat’ => 17,

All I need to a line of code where I can either enter the cat IDs or the slugs. I have 6 category types total and only want to display 4 of them in my list on the my page.

Thanks, Chris


Josh

  • Support Staff

September 26, 2014 at 12:25 pm

Hi Christopher,

You can use a native WP_Query() along with tax_query to get this done. Example code follows:

$args = array(
	'post_type' => 'espresso_events',
	'tax_query' => array(
		array(
			'taxonomy' => 'espresso_event_categories',
			'field'    => 'slug',
			'terms'    => array( 'category-a', 'category-b', ),
		),
	),
);
$wp_query = new WP_Query( $args );
Viewing 3 reply threads

The support post ‘Help with Template PHP Code’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso