Shortcode: Show total number of campaigns
-
Hello,
Based on this documentation – https://github.com/Charitable/Charitable-Stat-Shortcode
I’m trying to use a shortcode to show the total number of campaigns, but it shows nothing. The code I’m using is [charitable_stat display=campaigns], the other shortcodes are working, only this one has a problem.
-
Thanks for reaching out. I recently tested this personally on my Charitable 1.7.0.3 install and I did get a number to appear. I did the following:
– Created a shortcode block on a blank page.
– Added [charitable_stat display=campaigns]
– Published the page and I got a single number (for me it was 7).You didn’t mention how you were adding the shortcode – exactly what method are you trying? is it possible you can try this method? Note that this counts only published campaigns, not drafts.
You might want to confirm and view the source code to see if the number is being outputted but perhaps hidden by CSS or something else in your theme. You might also want to change to a default WordPress theme to confirm any issues are not related to your current theme.
Another suggestion might be to examine your PHP error logs to see if there is any errors being generated (more information on displaying errors on screen or in a log can be found here: https://www.ads-software.com/support/article/debugging-in-wordpress/)
Please also note that snippets and plugins in the Github repo are not officially supported by Charitable support, but we’ll do out best to help.
I’m using your Reach theme, but with any other it’s still not showing. All other shortcodes are working. You can see from my screenshots.
This is how I’m adding the shortcodes:
This is the missing value:
When I’m using one of the build in widgets, the campaign number valu is visible:
@rkovachev thanks for showing how you added the shortcode – it is similar to the method I was trying. But does adding that shortcode on a blank page produce the same result?
Can you confirm what version of Charitable (and any other Charitable plugins outside of the stats shortcode) you might be running, and also check out the error logs as per my previous suggestion? I am hoping that gives us a clue.
@wpcharitable
Yes, the same on blanc page.This is the error I have in the log:
[09-Nov-2022 11:32:39 UTC] PHP Notice: Charitable_Donation_Report::parse_report_type was called <strong>incorrectly</strong>. campaigns is not a valid donation report type. (This message was added in Charitable version 1.6.0.) in ..../wp-content/plugins/charitable/includes/deprecated/class-charitable-deprecated.php on line 149
I’m using the latest version of Charitable. All other Charitable plugins are deactivated and still the valu is missing.
@rkovachev thanks for that error message. it’s very odd, since that error shouldn’t be generating at all from what we can tell.
Can you do the following? Can you open up this file:
plugins/Charitable-Stat-Shortcode/class-charitable-donation-report.phpConfirm that “campaigns” is in the following near the top of the file around line 45.
private $types = array( 'amount', 'donations', 'donors', 'campaigns', );
If it is, for some unknown reason your input of “campaigns” isn’t matching up with that word. It’s something we cannot replicate the problem with.
If you can add two lines of code, clear your error log, and reload the front-end page a few times to generate additional information that might try to confirm our theory. These are the lines of code you can add around line 370, near the bottom of the file.
error_log( print_r( $report_type, true ) ); error_log( print_r( $this->types, true ) );
So here’s what it looks like surrounding the code that is already there:
if ( is_array( $report_type ) ) { return $report_type; } error_log( print_r( $report_type, true ) ); error_log( print_r( $this->types, true ) ); if ( ! in_array( $report_type, $this->types ) ) { charitable_get_deprecated()->doing_it_wrong
This is simply information gathering and seeing if this gives us any remaining clues. If this doesn’t bare any new information we might have to find an alternate method outside of this plugin of counting the “campaign” custom post type posts.
Sidenote: Before all of this try surrounding the word campaigns with quotes in the shortcode and see if this makes any difference. If not, remove the quotes and see if you can do the above. Thank you!
I’m not using a shortcode plugin, because it’s included in Charitable code – https://www.wpcharitable.com/documentation/stats-shortcode/
You pointed to documentation of a plugin that ADDS functionality to the shortcode in Charitable core (https://www.wpcharitable.com/documentation/stats-shortcode/), so that’s why we assumed you were using it.
https://github.com/Charitable/Charitable-Stat-Shortcode
That is actually a plugin that adds “Installing this plugin will give you access to some new features, not currently available with Charitable.” Displaying the number of campaigns is in bold in that documentation on Github, and as the documentation states “Extra parameters added by this plugin are highlighted in bold.”
So if you aren’t using the plugin on Github, you need to download it and activate it on your site.
Again as a reminder snippets and plugins in the Github repo are not officially supported by Charitable support, but we’ll do out best to help. But if this plugin from Github wasn’t being used that explains your issue. ??
The [charitable_stat] shortcode is now available in Charitable core.
This is what is written in the plugin description. I will try activate the plugin and check if it will be ok.
Installing the plugin fix the problem. But I think only the shortcode for counting the campaigns is missing from the Charitable core. Could you add it in the future update?
Yes I can see how that wording in the description on Github might be not clear enough. The [charitable_stat] shortcode IS IN CORE but the plugin on Github ADDS TO THAT PLUGIN.
We are currently considering in our roadmap how we can enhance the built-in core shortcode and part of that will be adding the enhancements to that shortcode from the Github plugin into a future verison of core.
I’m glad installing that Github plugin worked. I’m going to mark this as resolved. Please let me know if you have any further questions. Have a good day! ??
- The topic ‘Shortcode: Show total number of campaigns’ is closed to new replies.