Support

Home Forums Event Espresso Premium List events in a certain category on my home page

List events in a certain category on my home page

Posted: February 10, 2015 at 10:07 am


Michael Cain

February 10, 2015 at 10:07 am

Hi,

Looking for some help on displaying events from a certain category on my home page, without using a shortcode.

I’ve already got a dropdown box which is populated with all the events available, but I want to tailor this to show only certain events.

It’s set up as follows:

<?php 

              $args = array(
                'post_type' => 'espresso_events'
              );

              $the_query = new WP_Query( $args );

            ?>

            <?php if( have_posts() ): ?> 
            <select onchange="window.open(this.options[this.selectedIndex].value,'_top')" class="form-control">
			          <option value="">Please select a course...</option>
                <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
			          <option value="<?php espresso_event_link_url(); ?>"><?php the_title(); ?></option>
                <?php endwhile; ?>
			      </select>

            <?php wp_reset_postdata();?>

            <?php endif; ?>

This works great. I just need to know which parameter to add to the custom query to refine the result.

I tried ‘event_category’, ‘category_id’ and several others but to no avail – would appreciate any help!

Cheers
Michael


Michael Cain

February 11, 2015 at 2:01 am

Anyone? Really need to get this sorted. Would appreciate any help at all.

Thanks
Michael


Michael Cain

February 11, 2015 at 8:41 am

I solved my problem with the help of the following:

https://gist.github.com/joshfeck/e3c9540cd4ccc734e755

Spent hours searching but worth it in the end!

Hopefully will be of use to someone else.


Seth Shoultes

  • Support Staff

February 13, 2015 at 9:53 am

Hello Michael,

Thanks for sharing! I wish we could’ve helped you find and answer, next time we will try harder.


Michael Cain

February 16, 2015 at 4:01 am

No problem Seth 🙂


Philip Wall

February 16, 2015 at 7:53 am

Hi Michael,
I used the example on github you provided and it works a treat. How did you filter the results? ( I would like to filter by category(course location) and by the month the course is run.) Ideally the user could select this by dropdown box.


Michael Cain

February 18, 2015 at 7:13 am

Hi Philip,

Sorry for late reply. Glad you found the snippet useful too!

I didn’t actually filter the results to be honest, I only have a handful of events in each category, and as I just wanted a quick way to access them from my home page, I used the same query for both category types (just switching the ‘category_slug’ => ‘my-category-slug’, for the category I’d like to pull the info from.

One category displays each event horizontally with the featured image, title and link to the event, the other query pulls the event titles into a dropdown select field, which redirects to the event on selection.

Hope this helps?

The support post ‘List events in a certain category on my home page’ 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