Events+ in Multisite: "Category" is not recognized across subsites

Background and the Good News: I have Events+ activated in my main site, and several subsites (along with Post Indexer). I have been working with the [eab_calendar network="yes"] shortcode, as well as the [eab_archive network="yes"] shortcode and I have been able to make all events across the network display on any subsite that has Events+ enabled. All's good there.

The Bad News: I decided that I want to show events from a particular category in a list, so I figure I will use [eab_archive network="yes" category="webinars"]. This works just fine on the main site where the category was created, but it does not work on a subsite. On a subsite, the above shortcode just displays all the events from the entire network, without regard for the category they live in.

Is this the expected behavior? If so, is there a workaround or some sort of quick and dirty fix I can use? I really need to find a way to make this work. Thanks!

    kalico

    Hey Luís

    Dang...my happy dance turned in to a sad, mopey-face.

    I was duped into thinking it worked, because it showed one test item -- however, that item was on the same site and was being pulled in by the basic shortcode call [eab_archive], not by the "categories" argument.

    So in fact, there is just no content coming over at all from the other sites. It doesn't seem to recognize the category ID from a different site.

    I'm still noodling on this...but in the mean time, here are some specifics if you want to take a look.

    Category: "English Course"
    ID: 438
    Location: main site of multisite network ("NROC Network")

    SubSite: "Resources"
    Page: /resources/courses/nroc-english/
    Shortcode: [eab_archive categories="438"]
    On this page, you need to click the tab that says "Webinars" to see the output of the shortcode.

    BTW, I retitled my test event "WRONG ONE" and the event I'm trying to get "RIGHT ONE" because they were too similar before.

    Another note, if you look at that page, there is another item under the webinars tab. It's being posted by another means, and has nothing to do with this.

    kalico

    I have discovered more problems. I decided to test this by using the same shortcode on a page on the same site as the event. Many things don't work as I would have expected:

    Page on the Main site: /test
    I have two events in the category ID=438 : one archived in September 2015 and one open in May 2016.

    [eab_archive category="438"] - Displays only the open/future event in this category, which takes place in May 2016.

    What I want is for the list to show all the events, open and archived, from the category. So I tried this addon:

    Default to all Events - If no year or month arguments are passed to your archive page requests, this simple add-on will show all applicable Events instead of truncating them to montly archives.

    But it shows just the one upcoming event, not the past event.

    So then I turned that off, and started messing with date parameters. But my results were not what I expected, base on the instructions:

    [eab_archive category="438" date="2015-01-01"] - According to the shortcode instructions, "Starting date - default to now (date)" I would think that it would display all the events (open or archived) from that date to now. However, it displays no events.

    [eab_archive category="438" date="2015-09-01"] - By changing it to the month of the September event, I get that event to display. ONLY that event. So this date arg is not working as a "starting date"...unless by this shortcode you are only supposed to get archived events, not open events (but that is not what the instructions imply).

    [eab_archive category="438" date="2015-09-18"] - Since this date is AFTER the date of the event (which is on Sept 17), I would expect the event to not show up. However, it DOES show up. So it seems to be getting all the events for the month, without regard to the actual date in the arg.

    [eab_archive category="438" relative_date="-X months"] - according to the instructions "A date relative to now or to date argument (strtotime-compatible string)" but it still only captures events from THE month in question, not everything from that starting point. If I put -9 months, I get nothing. If I put -8 months, I get my September event (because it's 8 months ago, relative to now).

    So, in the end, I pretty much have nothing that works the way the instructions suggest, and still nothing that I can actually use on my site.

    What I really want is a list of ALL the items in my category, and some way to determine if I will get past or future events.

    I really hope you can help.

    Luís

    Hi kalico ,

    Hope you're doing well today!

    Let me try split all the questions:

    1) [eab_archive network="yes" category="webinars"]

    Sorry, I misunderstood too. After more tests I was able to check that, the shortcode it's not "respecting" the categories and is showing all the events, independently of the "category" defined in the parameter.

    So, I've confirmed this bug and flagged the developer so they can get it fixed up asap. Either myself or the developer will reply back here once we have pushed a fix out.

    2) Regarding to the "Default to all Events" add-on, it will only show all the "applicable" events, so, I think it will not show the events with the status "archived" only the "open" events.

    3) [eab_archive category="438" date="2015-09-18"]

    I think it's supposed to show all the events (including the events with the "archived" status), because we have other shortcode to show the expired events.

    I already flagged the developer regarding to the questions 2 and 3, to get their valuable feedback.

    I hope have replied to all questions!

    Cheers, Luís

    Luís

    Hi kalico ,

    After speaking with the developer, the "Default to all Events" add-on should be display all events. So using the archive shortcode with this add-on, it's supposed to show all events (past and future).

    So, I've confirmed this bug and flagged the developer so they can get it fixed up asap. Either myself or the developer will reply back here once we have pushed a fix out.

    If you have any further questions in the meantime just let us know.

    Cheers, Luís

    Ash

    Hello kalico

    Categories attribute doesn't work when you use network mode in the shortcode. The reason is, the category IDs are different in every subsites, plus we need to go through the whole network for those IDs or slugs, then need to go through all events, so if you have lots of subsites it will increase the runtime.

    But if you still want to do that, I have a solution for you. Please go to /wp-content/plugins/events-and-bookings/lib/class_eab_shortcodes.php line no 218 and add the following:

    if( $args['network'] && is_multisite() && $args['categories'] )
                    {
                        if( $args['categories']['type'] == 'id' )
                        {
                            if( count( $args['categories']['value'] ) > 1 )
                            {
                                $sites = wp_get_sites();
                                $cats = array();
    
                                foreach( $sites as $site )
                                {
                                    switch_to_blog( $site['blog_id'] );
    
                                    foreach( $args['categories']['value'] as $cat )
                                    {
                                        $term = get_term( $cat, 'eab_events_category' );
                                        if( $term->slug != '' )
                                        {
                                            $cats[] = $term->slug;
                                        }
                                    }
    
                                    restore_current_blog();
                                }
                            }
                        }
    
                        $modified_events = array();
                        foreach( $events as $event )
                        {
                            switch_to_blog( $event->blog_id );
    
                            $terms = wp_get_object_terms( $event->ID,  'eab_events_category' );
                            $t = array();
                            foreach( $terms as $val )
                            {
                                $t[] = $val->slug;
                            }
    
                            $commonElements = array_intersect( $t, $cats );
    
                            if( count( $commonElements ) > 0 )
                            {
                                $modified_events[] = $event;
                            }
    
                            restore_current_blog();
                        }
    
                        $events = count( $modified_events ) > 0 ? $modified_events : $events;
                    }

    To make more clear, the above should be added between the lines

    $events = ($args['network'] && is_multisite())
    			? Eab_Network::get_upcoming_events(30)
    			: Eab_CollectionFactory::get_upcoming_events($args['date'], $query)
    		;

    and

    $output = Eab_Template::util_apply_shortcode_template($events, $args);

    Hope it helps Please feel free to ask more question if you have any.

    Cheers
    Ash

    kalico

    Hi Ash I tried this and didn't get the results I was looking for.

    I tried:

    [eab_archive network="yes" category="107"]
    [eab_archive network="yes" category="english-course"]

    ...both of these options just gave me a list of all the events in the network, regardless of category.

    The page I was testing on is on the main site of the network:

    http://june.nrocnetwork.org/professional-development/webinars/

    and the category of events I was targeting is on a subsite (/resources).

    All that being said, I suspect that the real root of this problem is not in the code you provided me.

    I suspect it has something to do with the "network=yes" problem that Ivan Shulev is investigating for me.

    I say this because I noticed that -- like everywhere else I use network=yes -- the admin bar changes to reflect a different site than where the page actually lives.

    So maybe that problem has to be resolved before this will work.

    Thoughts?

    Ash

    Hi kalico

    I thought you are checking in eab_calendar shortcode, I didn't try for eab_archive shortcode. As I said in my previous reply, categories param won't work when you use network="yes".

    Would you please check with eab_calendar shortcode if that works? And please confirm if you need eab_archive too, then I will try to implement the same logic for this shortcode too.

    Have an awesome day!

    Cheers
    Ash

    kalico

    Hi Ash - I totally understand....I have been raising issues from too many places to keep track! But yes, this post was about [eab_archive] (I had to go back and read to be sure!). In my original post, I mentioned that [eab_calendar] was working fine, and I expected [eab_archive] to do the same, but it didn't. Probably my bad for not understanding the capabilities of each.

    So in the end, yes....if you can help me implement this functionality for categories in [eab_archive] it would be AMAZING

    (PS sorry for the previous post -- something went sideways with my connection to WPMUDEV and when it came back, I was logged in with my old account!?!)

    Ash

    Hello kalico

    I am sorry that I misunderstood.

    To make eab_archive working, please go to /wp-content/plugins/events-and-bookings/lib/class_eab_network.php line no line no 75 and add the following function:

    public static function get_archive_events ($limit=5) {
    		if (!eab_has_post_indexer()) return array();
    		$limit = (int)$limit ? (int)$limit : 5;
    
    		global $wpdb;
    		$result = array();
    		$count = 0;
    		$pi_table = eab_pi_get_table();
    		$pi_published = eab_pi_get_post_date();
    		$pi_blog_id = eab_pi_get_blog_id();
    		$pi_post_id = eab_pi_get_post_id();
    		$raw_network_events = $wpdb->get_results("SELECT * FROM {$wpdb->base_prefix}{$pi_table} WHERE post_type='incsub_event' ORDER BY {$pi_published} DESC");
    		if (!$raw_network_events) return $result;
    
    		foreach ($raw_network_events as $event) {
    			if ($count == $limit) break;
    			switch_to_blog($event->$pi_blog_id);
    			$post = get_post($event->$pi_post_id);
    			$tmp_event_instance = new Eab_EventModel($post);
    			$tmp_event_instance->cache_data();
    			if (!$tmp_event_instance->is_archived()) continue;
    			$post->blog_id = $event->$pi_blog_id;
    			$result[] = $post;
    			$count++;
    			restore_current_blog();
    		}
    		return apply_filters( 'eab_get_upcoming_events', $result, $limit );
    	}

    Then, go to /wp-content/plugins/events-and-bookings/lib/shortcodes/class-eab-archive-shortcode.php line no 59 and add the following:

    if( $this->args['network'] && is_multisite() && $this->args['categories'] )
                    {
                        if( $this->args['categories']['type'] == 'id' )
                        {
                            if( count( $this->args['categories']['value'] ) > 1 )
                            {
                                $sites = wp_get_sites();
                                $cats = array();
    
                                foreach( $sites as $site )
                                {
                                    switch_to_blog( $site['blog_id'] );
    
                                    foreach( $this->args['categories']['value'] as $cat )
                                    {
                                        $term = get_term( $cat, 'eab_events_category' );
                                        if( $term->slug != '' )
                                        {
                                            $cats[] = $term->slug;
                                        }
                                    }
    
                                    restore_current_blog();
                                }
                            }
                        }
    
                        $modified_events = array();
                        foreach( $events as $event )
                        {
                            switch_to_blog( $event->blog_id );
    
                            $terms = wp_get_object_terms( $event->ID,  'eab_events_category' );
                            $t = array();
                            foreach( $terms as $val )
                            {
                                $t[] = $val->slug;
                            }
    
                            $commonElements = array_intersect( $t, $cats );
    
                            if( count( $commonElements ) > 0 )
                            {
                                $modified_events[] = $event;
                            }
    
                            restore_current_blog();
                        }
    
                        $events = count( $modified_events ) > 0 ? $modified_events : $events;
                    }

    Hope it helps Please feel free to ask more question if you have any.

    Cheers
    Ash

    kalico

    Hi Ash Thanks for that, but something about this code gave me the dreaded WSOD

    If the code is fine, maybe I put it in the wrong place. You just gave line numbers.....should it be after or before? Those were both blank lines (one is the end of the file) so I just added it in at that point -- but maybe something is different about mine. Maybe you can clarify exactly where to put it (code reference instead of line #?) then I can try again.

    kalico

    Hey Ash - something is funky about this.

    I don't have a file in /lib called class_eab_archive_shortcodes.php

    I do have one called class_eab_shortcodes.php

    So my first mistake was not realizing that I put the code into a different file than you told me to. The names were close and I overlooked it. So I'm sure that's why I got the WSOD.

    To check the situation further, I downloaded v1.9.2 of Events+ (most current available on WPMUDEV) and looked at the files, in case I had somehow deleted something. But that version does not have that file either. The new file you sent me doesn't even resemble the existing file with a similar name, beyond the first few lines.

    Just for giggles, I decided to upload the new file to the /lib directory and just see what happens. At worst it will break, or it might be ignored, or it might just work.....

    OK, no WSOD.

    Now I upload the new class_eab_network.php file.

    No WSOD for that one either.

    So let's see if that did anything....

    Nope. Testing still doesn't give me any different results than I had before. I've tried the following on a test page on the main site:

    http://june.nrocnetwork.org/test-network-events-by-category/

    category="english-course"   
    
    categories="433,107"

    where "english-course" is a category on another site in the network (/resources), that has two events in it, and

    433 is the ID of the "professional-development" category on the main site (1 event), and

    107 is the ID of the "english-courses" category on the /resources site (2 events)

    With both options, I get all events from the network, not sorted by date, but by type (recurring events first, those are sorted by date within themselves, then other events sorted by date)

    So it seems like the file is being ignored completely. That's better than WSOD, but....

    Guess it's back to you now, to figure out whether that file belongs here somewhere, or what else is going on.

    Thanks again for all your work on this

    P.S. I removed the files, and set everything back to how it was on my site. If you need to test on my site, I can put it back up.

    Ash

    Hi

    I think I know what happened. Our developer is working on next release. So, I took the development version and worked on it, so files can be changed. The development version I have, the file is in there.

    So, if you want the development version, I can give you that if you want (but you may need to make some changes manually again), or I can work on the current release but it will need till Monday (sorry most of our staffs are on WCEU, so we are loaded with work ).

    Please let me know how you want it

    Have a good day!

    Cheers
    Ash

    kalico

    Hi Ash Thank you so much for that! I have it running on my site now, and I re-instated the changes you provided in the two additional files provided above.

    I have tested and here are my findings. Unfortunately, I didn't have success....and even have a recurrence of an old issue.

    1) Using the test page on the main site (/test-network-events-by-category) and the following shortcodes, I get all events from the network, without regard to category. I am also getting old events that have the status "archived".

    [eab_archive network="yes" category="107"]
    [eab_archive network="yes" category="english-course"]
    [eab_archive network="yes" categories="433,107"]

    where
    - "english-course" is a category on another site in the network (/resources), that has two events in it, and
    - 433 is the ID of the "professional-development" category on the main site (1 event), and
    - 107 is the ID of the "english-courses" category on the /resources site (2 events)

    2) Weirdly, I also got a regression to an old issue: the admin bar that displays when using "network=yes" in shortcode is from a different site than where the page actually lives. This issue had been resolved "magically" by changes to Post Indexer, which you recommended to fix a problem with E+.

    Please see the following posts:
    - You provide fix for E+ issues that are actually rooted in Post Indexer, then....
    - problems with admin bar association on network-wide E+ shortcodes are magically fixed after seemingly unrelated code change to Post Indexer.

    Sorry to add another layer to this, but that's what I'm seeing. I didn't make any changes to Post Indexer since that time, and the only change to E+ is what I described here. Thanks, as always, for your excellent assistance.

    Ash

    Hey kalico

    Would you please try the attached one?

    Please note that, you can use like:

    [eab_archive network="yes" category="107"]
    [eab_archive network="yes" category="english-course"]
    [eab_archive network="yes" categories="433,107"]

    You can't use:

    [eab_archive network="yes" categories="slug1,slug2"]

    About the admin bar issue, with the changes in Post Indexer, this is not possible to be fixed. So I believe the reason was different. Would you please post in that thread so that Ivan Shulev can check that issue? Feel free to tag me if you need

    Have a good day!

    Cheers
    Ash

    kalico

    Hi Ash I'm sorry to say that I'm not seeing any different results from this version. The "network" argument is recognized, but not the "category/ies". I've tried it many different ways, and I just get a dump of events from the network. I'm not even sure exactly what parameters it's using to decide which ones to display, because it seems inconsistent.

    And while I know you said there should be no connection, the beta version consistently reintroduces the "different admin bar/network=yes" problem. It goes away when I revert to 1.9.2.

    I realize there could be some other issue causing this, but ever since I made the recommended changes to Post Indexer, the problem has been gone -- until I activate E+ 1.9.3 beta.

    But of course, we also must keep in mind that Post Indexer is behaving oddly. It no longer has graphs, and it still refuses to index CustomPress custom post types.

    I would have to go through all of my tickets (which I can't do right now....) and see if I made any other recommended changes to E+ 1.9.2 that might be the real solution to the admin bar/network problem....i.e., changes that were recommended, but not yet incorporated into 1.9.3. However, the change happened so very obviously as soon as I implemented the changes to Post Indexer, so it certainly seems to be the root of the problem.

    Sorry I don't have better news! Thanks for all your efforts on this.

    Ash

    Hello kalico

    Okay, let me dig into this then

    Would you please send me your admin login, ftp login and cpanel login details? Also point out all of your issues regarding Events+, I will go through all of them and check what I am missing Please point out the issues like 1, 2, 3 etc. Also explain how I can replicate the issue in detail.

    To send me details, please use our contact form: https://premium.wpmudev.org/contact/

    Select: I have a different question
    Subject: Attn-Ash (this ensures that it will be assigned to me)
    Details:
    1. Send all requested details
    2. Send a link of this thread so that I can track
    3. Send any other relevant link

    I will be happy to take a look

    Cheers
    Ash

    kalico

    No, I'm sorry...there is no way around this as it's a security precaution. Believe me, I've asked my IT team and they are insistent.

    Your IP doesn't have to be static, necessarily. Most people even with a dynamic IP have an address that changes every few weeks (i.e., when they reconnect to the server), not every few hours, so it's usually something that can be arranged.

    You (or Ash) can go to http://whatismyip.com to find out what yours is, and send me that. It usually lasts long enough, but of course it depends on your service provider/office network/etc. I don't know what your situation is there, but a while back Ivan Shulev gave me an IP address for himself, so perhaps there is a way if you ask around internally.

    Thanks!

    kalico

    Hi Kasia Swiderska Can we clarify who is working on what? Adam and Ash both are trying to access my site for different reasons right now (I just heard from Adam this morning about it)....and I think that for Ash, it's for this issue/thread. If there needs to be more than one person for an issue, that's fine. I just need to know what each person is responsible for, and be sure there are no conflicts.

    Thanks!

    P.S. The thing with Ivan was a while ago, on a different issue. I just mentioned it because he seemed to know how to identify which IP address to use.

    kalico

    Hi Kasia Swiderska Thank you for your efforts to help with this process I am a little unsure how access to your shell will help Ash, so let me ask this: If he wants to use an FTP client like Filezilla or use a web browser to access phpMyAdmin, will he be able to do those things and still use your static IP address?

    Our server has to recognize that his requests are coming from that IP address, or it won't allow him to work....but he needs to be able to use client apps like Filezilla and a browser, not SSH.

    Thanks

    Kasia Swiderska

    Hello kalico,

    If he wants to use an FTP client like Filezilla or use a web browser to access phpMyAdmin, will he be able to do those things and still use your static IP address?

    No. This will be not possible because he will need to use console and tools that are available there (so editors like nano, vi). With console he can also connect to database but it will be harder to operate on it (still it is possible). Clickable tools are out of question when using ssh through shell account.

    Let me brainstorm this with Ash again and see if there is some other solution.

    kind regards,
    Kasia

    kalico

    Thanks for the clarification, Kasia Swiderska Personally, I use the shell all the time (and almost exclusively), but what confused me about your initial comment is that -- for me -- while using shell, I am still on my regular computer, and I am using my usual ISP, and I can also switch over to the browser or to another app like Filezilla, and never change the IP address I'm on. All the while, if I were to go to http://whatismyip.com, I would always have the same IP address that I'm connecting on, regardless of which application I'm using.

    So I was hoping that if Ash was using your shell access, he would also be able to use your browser and other apps on your computer, all from your static IP address (even if it's only stable for a few days at a time, that's better than changing with every login, as Ash described).

    I'm still a bit confused as to why no one at WPMUDEV seems to have access to an internet connection that stays stable long enough to have an IP address for more than a few hours at a time. Of course, I do understand that you are a distributed workforce (my company is, too) so your internet access will vary from person to person, across many miles and many providers. I'm sure that's part of the problem.

    From my company's side of things, we can't allow access to ever-changing IPs, because of security. For example, we can't allow someone to access our servers when they are working at a coffee shop, because that's not secure. So we need to know a stable IP address that you work from regularly, that is tied to a normal ISP, to get some degree of confidence that the connection is secure.

    Ash did give me an IP range we could open up, that would allow him access -- however, my IT manager pointed out that this range encompasses some 16 MILLION servers, including a large block of servers in China -- which is about as not-secure as it gets, lol

    We're still working on some options on our side, so as I hear more from my team I'll update you guys. Thanks