Home Forums Event Espresso Premium Hide a Category Shortcode Needed

Hide a Category Shortcode Needed

Posted: February 9, 2019 at 10:40 am


February 9, 2019 at 10:40 am

I didn’t see an option for a feature request anywhere, so I’m just posting this on the forum. I too really need the ability to hide certain event categories from a calendar (as per described here: Unfortunately, I don’t think the custom PHP script offered won’t work as is, because for my use I need to have a “second” special use calendar on my website that displays events for just one category (which is enabled by the event_category_id= shortcode), however, I also need to EXCLUDE this category from my primary calendar.

The interim solution is to use the “show” shortcode for all my categories except the one I don’t want on my primary calendar, but this is cumbersome and not an ideal long-term solution.

I hope this is a capability EE can consider for a future release.


February 9, 2019 at 4:48 pm

Figured I’d share that interim solution I decided to pursue was to establish a “default” category that all my normal events are included in, and use that category id with the event_category_id= parameter in the primary calendar. The trick is I just have to remember to check that category box for every new event.


  • Support Staff

February 11, 2019 at 9:22 am


This code snippet should work for your use case because it’s intended to hide a category conditionally, depending on the current page. In other words, you can remove a specific category for your primary calendar page.


February 11, 2019 at 10:36 am

Hi Josh,

I have a couple of question about that snippet, specifically about line 12 and line 20. My perception is line 20 is where I put the category ID I want excluded from my primary training calendar (or multiple ids, separated by commas, it appears). But regarding line 12; I don’t recognize under the function of the term_relationships or term_taxonomy_id elements.

Also, it’s unclear to me how this code distinguishes which calendar I want it to apply towards?


  • Support Staff

February 11, 2019 at 10:55 am


You don’t actually change line 20. Line 12 is where you put the category ID. The example code on line 12 is removing event category ID 12.

The other code you change is on line 19, where the example has:
if(is_front_page()) {
If your main calendar is on the home page, then you don’t change the code on line 19. If the main calendar is on another page, then you’ll change the code on line 19 to something like if(is_page(123)) { where 123 is the page ID.


February 11, 2019 at 12:28 pm

Below is the code I tried based on your guidance, but the events I want to exclude (event_category_id=67) from the calendar are still appearing.

I tried changing “term_taxonomy_id” to “event_category_id” – no effect. I tried changing “is_page” to is_post” – and that threw an error. I don’t know what else to try next? Just to clarify, is this code actually intended to work with the calendar and not specifically the events table?

function ee_remove_category_event_list( $SQL, WP_Query $wp_query ) {
    global $wpdb;
    if ( 
        isset( $wp_query->query_vars['post_type'] ) && 
        ( $wp_query->query_vars['post_type'] == 'espresso_events'  ||
        ( is_array( $wp_query->query_vars['post_type'] ) && 
        in_array( 'espresso_events', $wp_query->query_vars['post_type'] ) ) ) &&
        ! $wp_query->is_singular ) {
            $SQL .= " AND ID NOT IN (SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id=67)";
    return $SQL;
add_action('loop_start', 'ee_test_home_page_filter');
function ee_test_home_page_filter() {
    if(is_page(227)) {
        add_filter( 'posts_where', 'ee_remove_category_event_list', 25, 2 );


  • Support Staff

February 11, 2019 at 7:33 pm

I tried changing “term_taxonomy_id” to “event_category_id” – no effect.

You don’t change that part, because event_category_id isn’t a valid parameter.

How about we try a different approach? You can use this custom snippet instead:


February 13, 2019 at 9:43 am

Tried it and received a “nonce_failure” error upon Update File on the Edit Themes page (via WP Menu -> Appearance -> Editor -> functions.php [child]


  • Support Staff

February 13, 2019 at 9:45 am

You can avoid the nonce_failure, and avoid bringing down your entire site if you make a mistake, by using a code editor & FTP to edit code.

Generally speaking, the code editor that’s built in to WordPress should never be used for editing PHP code.


February 13, 2019 at 9:57 am

I wasn’t aware of that – good to know.

In the meantime, I got it work – thank you!

The support post ‘Hide a Category Shortcode Needed’ 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.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  mdeyerinkc 6 months, 1 week ago ago

Topic Tags


This topic is: resolved
Do NOT follow this link or you will be banned from the site!