Okay
  Public Ticket #1992868
Filters
Closed

Comments

  • Marian started the conversation

    so I have the short code showing only a few categories but when people click on filter. they can see all of them. is there a way to exclude the categories not listed from showing?

    I tried just hidding it with css but because some of my most have more than one category if people uncheck one if it has more than one category it will continue to show because of the second category.

    I tried something I saw on the forums:

    <script type="text/javascript"> 
    add_filter('wp_footer', function() {
        ?>
        <script type="text/javascript">
            (function ($) {
                $(function () {
                    $.stecExtend(function (master) {
                        
                        var exclude_category = [27,26]; 
                        
                        var events = master.calData.filterGetEvents;
                        var filtered = [];
                        
                        if (master.glob.options.view == 'agenda') {
                            $.each(events, function () {
                                if ($.inArray(parseInt(this.calid, 10), exclude_calendars) == -1) {
                                    filtered.push(this);
                                }
                            });
                        }
                        master.calData.filterGetEvents = filtered;
                    }, 'beforeProccessGetEvents');
                });
            })(jQuery);
        </script>
        <?php
    });
    </script>

    but this did not work.


    I just don't know how to deactivate a category or two. please help!


  • Marian replied

    Just checking back on this ticket. I really need to get this corrected in the next couple of days.

  •  94
    Valentin replied

    Hello Marian, 

    I'm really sorry for the delays we are preparing our next big update to go live later today and doing final tests. The developer will contact you soon.

    Stachethemes Support
    My Time Zone is GMT+3


    Envato Profile | Facebook | Twitter | Newsletter | Rate & Review

  • Marian replied

    Alright Valentin, 

    Thank you for the update.

    -Marian

  •  894
    Zhivko replied

    Hi,

    In your theme functions.php at the bottom add this code:

    add_filter('wp_footer', function() {
        ?>
        <script type="text/javascript">
            (function ($) {
                
                if (typeof $.stecExtend !== 'function') {
                    return;
                }
                
                $.stecExtend(function (master) {                 var exclude_category = [1,2,3,4,5,6];                 var events = master.calData.filterGetEvents;
                    var filtered = [];
                    
                    $.each(events, function () {
                        var event = this;
                        $.each(event.category, function(){
                            var catid = parseInt(this.id, 10);
                            if ($.inArray(catid, exclude_category) === -1) {
                                filtered.push(event);
                            }
                        });
                    });
                    master.calData.filterGetEvents = filtered;
                }, 'beforeProccessGetEvents');
            })(jQuery);
        </script>
        <?php
    });


    Replace 1,2,3,4... with your category ids you want to exclude

    var exclude_category = [1,2,3,4,5,6];

    Stachethemes Developer

  • Marian replied

    Hello Zhivko,

    Thank you!

    I have added this as instructed. Here is a link to the screenshot of where I added it. it is not doing much though. Any idea why?


  •  894
    Zhivko replied

    Delete the code I've sent you earlier and try out this one:

    add_filter('wp_footer', function() {
        ?>
        <script type="text/javascript">
            (function ($) {             if (typeof $.stecExtend !== 'function') {
                    return;
                }             $.stecExtend(function (m) {                 var exclude_category = [26, 27];                 $.map(m.calData.eventsPool, function (event, i) {                     var categories = event.category;
                        var found = [];                     $.each(categories, function (k) {
                            if ($.inArray(parseInt(this.id, 10), exclude_category) !== -1) {
                                found.push(k);
                            }
                        });                     if (found.length > 0) {
                            if (categories.length > found.length) {
                                $.each(found, function () {
                                    delete (m.calData.eventsPool[i].category[this]);
                                });
                                m.calData.eventsPool[i].category = m.calData.eventsPool[i].category.filter(Boolean);
                            } else {
                                delete (m.calData.eventsPool[i]);
                            }
                        }                 });                 m.calData.eventsPool = m.calData.eventsPool.filter(Boolean);                 m.$instance.$top.find('.stec-top-menu-filter-by-category ul li').each(function () {
                        var catid = parseInt($(this).attr('data-catid'), 10);
                        if ($.inArray(catid, exclude_category) !== -1) {
                            $(this).remove();
                        }
                    });             }, 'onAddToEventsPool');
            })(jQuery);
        </script>
        <?php
    });


    Stachethemes Developer

  • Marian replied

    works perfectly!

    Thank you!