Show only events attributed to a certain Category or Speaker

Home Forums Calendar Products Events Calendar PRO Show only events attributed to a certain Category or Speaker

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #930587
    simoncarr
    Participant

    Is there a method with PHP or Shortcodes to filter which events display?

    I’m building a site where there are ‘Author’ pages, and I would like to place some code on those pages which displays a list of events for that Speaker / Author only.

    In another area of the site I would need to do the same thing, but only filter based on Venue or Location.

    Any advice for how to accomplish this?? Many thanks!

    #930694
    George
    Participant

    Hey Simon!

    There is indeed some PHP you can use to get events with the specific parameters you described in your post here. If you ensure you’ve got solid backups of your site and database so you can play around a bit, I’m sure if you spend some time with the things I’m about to recommend you can cook up exactly what you need for your site.

    First, I’d recommend reading up on tribe_get_events() function here → https://theeventscalendar.com/knowledgebase/using-tribe_get_events/

    It’s a pretty powerful, but simple, function to use, and as you can see, it lets you get pretty specific with what type of events to “get”.

    To get really specific with authors, specific venues, etc., however, that article alone isn’t enough. To learn how to specify these things in your Events queries, I’d recommend getting familiar with WP_Query, which is the class within WordPress itself that tribe_get_events() ultimately references.

    You can learn about WP_Query in-depth here → http://codex.wordpress.org/Class_Reference/WP_Query

    If you notice on the tribe_get_events() article I linked you to above, that article itself doesn’t specifically mention how to specify an Author in the Events query. <b>But</b>, since tribe_get_events() ultimately calls WP_Query itself, you can use almost any of the parameters for WP_Query in your tribe_get_events() parameters.

    For example, here’s an example from the tribe_get_events() article that queries 5 upcoming events:

    // Retrieve the next 5 upcoming events
    $events = tribe_get_events( array(
    'posts_per_page' => 5,
    'start_date' => new DateTime()
    ) );

    If you want to additionally limit this query to only get 5 upcoming events from a specific author, find the Author’s ID within WordPress and consult the “Author Parameters” section of the WP_Query article I Linked to above. If the Author ID you wanted to specify was 123, for example, you could modify the above query example to this:

    // Retrieve the next 5 upcoming events
    $events = tribe_get_events( array(
    'posts_per_page' => 5,
    'start_date' => new DateTime(),
    'author' => 123
    ) );

    Does that make sense? If not, let me know what sort of things aren’t clear and we’ll try to clarify the advice a bit.

    You can use just about any of parameters in that WP_Query article in your tribe_get_events() query – so, for example, “Venues” in Events Calendar are custom taxonomies, so consult the Taxonomy Parameters section of that WP_Query article above and play around with that a bit.

    We can only provide limited support for customization stuff like this, but I hope I was thorough enough to help you get started on things. Please let me know if anything’s not clear or if you have any other questions or concerns!

    Thanks,
    George

    #931691
    simoncarr
    Participant

    Thanks for the help George.

    I’m getting closer to having this resolved. Below is some code that I am using – it seems to work, but once this is placed within my Genesis template it fails. Any ideas why that would be?

    <?php
        global $post;
        $all_events = tribe_get_events(array(
            'eventDisplay'=>'upcoming',
            'posts_per_page'=>4,
            'tax_query'=> array(
                 array(
                    'taxonomy' => 'tribe_events_cat',
                    'field' => 'slug',
                    'terms' => 'category-slug'
                    )
                    )
                    ));
    
    foreach($all_events as $post) {
        setup_postdata($post);
    ?>
    #931697
    simoncarr
    Participant

    Or – could it be that this kind of custom filtering only works with the Pro plugin and not the regular one?

    #931769
    simoncarr
    Participant

    I was able to isolate the error that I was having..

    But as a follow up question — How can I display the Event Cost and Website link within the tribe_get_events array?

    #932090
    George
    Participant

    Hey Simon,

    Cool, I’m glad you’ve been able to work through some of these issues here. We unfortunately can’t offer specific support for customizations like this, but the good news is that your final two questions here are examples of things you can find by searching – either here on the theeventscalendar.com, or by searching on Google with site:theeventscalendar.com at the end of your search query to limit the search to theeventscalendar.com.

    Getting event cost, for example, should be something you can accomplish just by using the function tribe_get_cost(). You can find that here → https://theeventscalendar.com/function/tribe_get_cost/

    And as for getting the “Website Link” field: if you mean the Website Link for your given venues, again, searching online is the best thing to do here – we’ve got yet another function that easily grabs that data, check it out here: https://theeventscalendar.com/function/tribe_get_venue_website_link/

    Since your original questions are mostly answered here and the rest of customization tweaking is something that you’ll have to take the reins on, I’ll mark this issue “resolved”. However, I’ll still leave the ticket open so you can respond and confirm, or comment on other issues or concerns if they’re within the scope of support we can provide. And if problems or questions pop up at any time, you can always come right back and open a new ticket here on the support site 🙂

    Best of luck with your customizations! Be sure to make backups of your custom code and of your site and database while you play around with things, and definitely play around with the new search functionality here on theeventscalendar.com – there’s a ton of great information and articles here.

    Cheers,
    George

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Show only events attributed to a certain Category or Speaker’ is closed to new replies.