Support

Home Forums Event Espresso Premium Calendar – Limit Categories in Dropdown

Calendar – Limit Categories in Dropdown

Posted: October 19, 2015 at 1:30 am


Mark Johns

October 19, 2015 at 1:30 am

Hi,

Just after some assistance with the following query if possible.

I am using sub-categories to allocate different colours to individual events. This is ok however I can’t have the sub-categories displaying in the calendar dropdown. If I could please be directed to the code for displaying the category dropdown, so I can limit to show only top level parent categories, it would be greatly appreciated.

Thank-you


Josh

  • Support Staff

October 19, 2015 at 3:36 pm

Hi Mark,

The code that displays the category dropdown is in the calendar add-on’s EED_Espresso_Calendar.module.php file. I do not advise directly editing the file, and if you review the code you’ll note that it’s looping through all the taxonomy terms for event categories, which by the way are not hierarchical.

What I would suggest instead of modifying that loop is add some jQuery to the calendar page that hides each of the categories from the dropdown. Something like this can be added to a functions plugin or into your WordPress theme’s functions.php file.

function my_remove_calendar_category_options() {
    if(is_page('calendar')) { // replace calendar with your calendar page's slug
    ?>
    <script>
    jQuery( document ).ready(function($) {
        $('#ee-category-submit option[value="category-to-remove"]').hide();
        $('#ee-category-submit option[value="another-category-to-remove"]').hide();
    });
    </script>
    <?php 
    }
}
add_action( 'wp_print_footer_scripts', 'my_remove_calendar_category_options');


Mark Johns

October 19, 2015 at 10:22 pm

Thank-you very much josh, that’s perfect. I inserted the code into the child theme functions and it worked perfectly. Thanks again πŸ™‚


Tony

  • Support Staff

October 20, 2015 at 4:04 am

Hi Mark,

I’m glad that worked for you.

If you need any further assistance just let us know πŸ™‚


Mark Johns

October 20, 2015 at 10:38 pm

Hi Tony,

Unfortunately it has stopped working.

Not sure what prompted this, I have updated expresso and added a .mo file to change some strings?

This is the php I have included in my child theme functions

function my_remove_calendar_category_options() {
if(is_page(‘youth-calendar’)) {
?>
<script>
jQuery( document ).ready(function($) {
$(‘#ee-category-submit option[value=”l1l2s”]’).hide();
});
</script>
<?php
}
}
add_action( ‘wp_print_footer_scripts’, ‘my_remove_calendar_category_options’);

This is the url it relates to http://ssa.marxdesign.com.au/youth-calendar/

Thank-you, your assistance is appreciated.


Tony

  • Support Staff

October 21, 2015 at 8:39 am

Hmm, I can’t see any reason for that to stop working.

It looks like you have disabled the category dropdown on the page above, if you’d like to test this on another page using the [ESPRESSO_CALENDAR] shortcode that isn’t set within your WP menu (and therefor away from view) we can view this on there.


Mark Johns

October 21, 2015 at 5:47 pm

Thanks Tony, we have set up a test page http://ssa.marxdesign.com.au/test-calendar. I updated the code in functions.php to suit this page’s slug but unfortunately still not altering the categories in the dropdown. Any suggestions would be great.


Josh

  • Support Staff

October 22, 2015 at 7:17 am

Hi Mark,

I checked both of the pages you linked to and the script is not loading, at all, anywhere on either of those pages. It looks like your theme has a custom JS script, so maybe they recommend placing custom scripts within that file? Another alternative is you can put the script right within a little functions plugin.


Mark Johns

October 22, 2015 at 4:58 pm

Hi Josh, thanks for the reply, I have tried adding the code in the custom JS of the theme and also creating a little functions plugin. Unfortunately I have been unable to get either of these options working. In the console the script returns SyntaxError: Unexpected token ‘?’ does it do the same on your end?


Tony

  • Support Staff

October 23, 2015 at 6:59 am

I don’t see any errors within console, but I also can not find the JavaScript from above within the page.

What method are you currently using?


Mark Johns

October 25, 2015 at 5:49 pm

Thanks for the reply Tony, hmm that’s strange, I have the code added in a custom plugin as directed above, the php file contains the below code:
<?php
/*
Plugin Name: Site plugin for ssa.marxdesign.com
Description: Site specific code for ssa.marxdesign.com
*/
/* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */

function my_remove_calendar_category_options() {
if(is_page(‘test_calendar’)) { // replace calendar with your calendar page’s slug
?>
<script>
jQuery( document ).ready(function($) {
$(‘#ee-category-submit option[value=”l1l2s”]’).hide();
$(‘#ee-category-submit option[value=”another-category-to-remove”]’).hide();
});
</script>
<?php
}
}
add_action( ‘wp_print_footer_scripts’, ‘my_remove_calendar_category_options’);

/* Stop Adding Functions */


Lorenzo Orlando Caum

  • Support Staff

October 26, 2015 at 10:55 am

Hi there Mark,

Is this a site specific plugin? If so, could you ensure that it is activated through WP plugins?

Also, please adjust your slug towards the beginning of the code snippet (i.e. change the underscore to a dash):

test_calendar –> test-calendar


Lorenzo


Mark Johns

October 26, 2015 at 7:33 pm

Thanks Lorenzo, the plugin is activated. I have corrected the slug and no difference unfortunately.


Mark Johns

October 26, 2015 at 8:11 pm

Good news, i did a bit of further investigating and have been able to get it to work using .remove(); rather than .hide();. Thanks for your help everyone πŸ™‚

The support post ‘Calendar – Limit Categories in Dropdown’ 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