Anniversaries using year_type=since doesn’t include current year
-
We are trying to use this plugin to show a block that has a list of upcoming anniversaries in this format: “John Doe 3 Year(s)” Right now we see what the anniversary date is currently. So if John Doe’s upcoming anniversary is his 3 Year anniversary it will say 2 Year(2).
Basically is there a way to advance the year count by 1 for anniversaries?
Here is the shortcode we are using:
[upcoming_list list_type=’anniversary’ show_title=false show_lastname=true no_results=’No Upcoming Anniversaries’ year_type=since]
-
I understand what you are attempting to do. It is possible to advance the year count by one, but this would require edits to the template’s PHP code. Is this something you feel comfortable attempting?
Yep. I can do that if I know the code I’m adding.
Open the
../wp-content/plugin/connections/templates/anniversary-light/anniversary-light.phpfile.Ok, place your cursor at the end of line 126 and hit enter/return to add a new empty line.
On that line, 127, add
$today->modify( '+1 year' );.Save the file.
Ensure the desired results.
If the are, then I recommend copy-pasting the file into the custom template override path:
I hope this helps; please let me know.
Following up…
Wondering how you made out with this change? Did it work for you?
I did some testing this morning and unfortunately things didn’t go according to plan…
I applied the line of code through WordPress’ Plugin File Editor and got a strange error that said “Error: Template Not Found” so I tried to revert the changes and see if that error went away, but once removing that line of code, it continued to say that error. Then I tried to specify template=’anniversary-light’ in the short code, but then it said “No,” which was the beginning of the no anniversaries text. Since the page was being talked about in our meeting this morning, I tried to just uninstall the Connections plugin and reinstall it (hoping that would just revert it to a working state), but that led to a full WordPress site crash. Thankfully I had a backup from earlier in the morning, so I restored to that just in time for the meeting.
So basically I’m back at square one. Is there a different way I should go about testing if the change to the plugin template file will work? I’m about to try again.
RE: I applied the line of code through WordPress’ Plugin File Editor and got a strange error that said “Error: Template Not Found” so I tried to revert the changes and see if that error went away, but once removing that line of code, it continued to say that error.
From the error description, it sounds like the
anniversary-light.phpfile contained a typo after the edit or became corrupt when WordPress attempted to save the change.My suggestion is not to use the Plugin Editor. Log in to the site using FTP, download the file, make the edit, and then upload the altered file.
I hope this helps!
I just tried this thinking the same thing. I used FTP to make the template override file in wp-content/connections-templates/anniversary-light/anniversary-light.php with the line of code added. I got the same result. Also I was unable to revert the change which led to a site crash again.
I’m no programmer, but how does the year get advanced by one if the datecode probably looks like 20220503 and the math operation is saying ‘+1 year’? (seriously, I’m not a programmer, so if this is stupid, disregard)
RE: I used FTP to make the template override file
Instead of making the template override file, please edit the source file.
RE: how does the year get advanced by one if the datecode probably looks like 20220503 and the math operation is saying ‘+1 year’?
The
$todayvariable is an instance of the PHP DateTime object and not a string of20220503. You can apply modifiers to the DateTime object. In this case, we’re saying today is actually +1 year from today, which should result in “John Doe 3 Year(s)” instead of “John Doe 2 Year(s)” (from your original given example).Editing the source file has the same effect. I get this error:
Then I am unable to revert the change. Uninstalling the plugin results in a full crash of WordPress.
Ahh. Now I understand the +1 year thing better. Thank you!
I’m going to try doing this on a completely blank WordPress site. I’m thinking it might be another plugin that is causing the issue maybe?
Can you please attach screenshots showing the path of the file edited and the changes made?
This change should not cause this error and should be reversible by undoing the change. And, uninstalling definitely should not cause WP to crash because, at that point, Connections and the file being edited are no longer being loaded by WP.
Do you, by chance, have any other code interacting with Connections code? Perhaps something running with the Code Snippets plugin or added to the theme’s
functions.phpfile?I agree. These changes should not have this effect. And reverting shouldn’t cause any of this to happen. I’m not sure what could cause this. (why I’m trying the blank site approach)
I’m not using Code Snippets and my site’s theme has not been modified. We are using Elementor’s Hello theme just as it comes.
Here are some screenshots of what I’m doing:
And just like that, it’s working… I literally just did everything I did over again for those screenshots and it worked… I am at a loss for how that could happen.
Thanks again for all your help. And sorry for wasting time. I did it the same way three times and the last one worked for some reason. I just added the modified file to the override directory and it’s still working.
I have no idea what I was doing wrong, but thank you!
Definitely, odd, and great to hear this is working for you. Happy to help!
The topic ‘Anniversaries using year_type=since doesn’t include current year’ is closed to new replies.