I think I have it sorted – [discourse_latest] isn’t a proper shortcode itself, I thought I saw it somewhere. I switched it to [discourse_topics source=“latest”] and it worked.
Sheepish grin
Ray
PS How can I change the date formatting on the latest topics that show on shortcode, @simon? It shows as 2020-10-20 and I’d rather have it say Oct-20 or similar.
I’m fairly sure that the shortcodes plugin uses the datetime format that is set on the WP Discourse Commenting options tab. Click the link in that setting’s description to see the available options for formatting dates.
Could you please add the usernames as avatars titles by default or as a shortcode option, and maybe another option to remove the username ( display_usernames = “false” ?). Meanwhile, if anyone needs this go to wp-discourse-shortcodes-master/lib/discourse-topic-formatter.php and replace
and throws the following error on the front-end: Warning : Invalid argument supplied for foreach() in /home/customer/www/web.com/public_html/wp-content/plugins/wp-discourse-shortcodes-master/lib/discourse-topic-formatter.php on line 94
If it helps anyone, the RSS feed of my community works just fine and lists all the topics. What could I be missing here? Help appreciated
Edit and update: It seems like the topics variable is not getting populated in code.
Line 94: foreach ( $topics as $topic ) {
.....
}
//Topic variable definition
if ( $use_plugin_formatting ) {
$topics = $discourse_topics['topic_list']['topics'];
}
I figured it out. The checkbox to show private posts was not enabled. Beyond that, the error can be solved by adding a condition for null value for $topics variable. I did that is worked just fine.
This is finally on the top of my list so I will be working on this plugin tomorrow, fixing some bugs and answering your questions. Sorry for the long delay.
I have thoroughly tested the plugin, fixed a few bugs, two of them having to do with failing to update the cache of the shortcode output, updated the readme and pushed a new version.
I still see one large issue where [discourse_topics] shortcodes with different categories do not work correctly. This will take quite an amount of work to fix. I will address that one first thing after my upcoming vacation.
I have only one shortcode in use in this instance, so I’m not sure if I should be having issues. I would like to show private topics, but only of certain categories (which are collected under a single parent category). Neither the single parent category ID (e.g. [discourse_topics category="5" ... ]) or each of the subcategory IDs (e.g. [discourse_topics category="6,7,8,9,17" ... ]) seems to limit the results to these categories (additional private topics are shown that should not be). I’m wondering if this is the currently expected behavior (that you’ll be addressing)?
A quick fix could be to disable the Display Private Topics checkmark in the settings tab. That won’t solve the issue of the wrong category(/ies) being selected but it will stop the private topics from appearing in Wordpress.
Can you please check your logs on Discourse side and search for the API call that is being made? The API call will be triggered when you edit and change the page on Wordpress side.
I couldn’t find any API calls in any of the Discourse logs. However, the good news is I think we might have solved it.
The original shortcode was using source="top" and some other parameters, so I slowly stripped the shortcode down until it was only using default settings by omission. I was under the impression that only source="latest" made use of a webhook per the language of the checkbox in the WP admin settings, but we enabled a webhook for latest topics (and additionally restricted the trigger to only the categories we wanted to show) and then when I added back in the parent category, the shortcode started respecting the category restrictions! (It didn’t respect the category restriction with source="latest" either until I enabled the webhook, despite clearing the cached HTML through the WP admin page, and other sources of caching we have for the site.)
After seeing the desired results using the webhook + source="latest", I changed the source back to “top” and then added the original parameters back in bit by bit. So far it has kept respecting the category restriction. I left the webhook enabled.
If the webhook is what is helping (still, and not just something that served as a reset of sorts), I suggest changing the wording of the WP admin page from “Use a Discourse Webhook to refresh the ‘latest’ topic list” to “Use a Discourse Webhook to refresh the [discourse_topics] list” (or something else to make it clear it doesn’t matter which source you’re using in the topics list, the webhook is likely to be the cure-all elixir we are looking for).