The List Category Posts shortcode works just fine in GP Hooks like this:
[catlist name="cat1" date="yes"]
However, when the name is passed as a PHP variable via the ‘After Content’ GP Hook, the shortcode does not work. Here’s my code:
<?php
$categories = get_categories();
global $post;
$post_slug = $post->post_name;
foreach ($categories as $category) {
$category_slug = $category->slug;
$category_name = $category->name;
if ($category_slug == $post_slug) {
if ($category_slug == 'cat1') {
echo ('<br>');
echo do_shortcode ('[catlist name="' . $category_slug . '" date="yes"]');
echo('(Category slug = ' . $category_slug . ', Post slug = ' . $post_slug . ')');
} else {
echo ('<br><br><h2>' . $category_name . ' News</h2>');
echo do_shortcode ('[catlist name="' . $category_slug . '" date="yes"]');
}
}
}
?>
You can see an example of the correct and incorrect outputs (provided in the Website URL field below)
I’ve switched off the cache too to exclude that as the issue. And, I’ve sought help from the plugin developer, but they were unable to help: https://wordpress.org/support/topic/catlist-in-php-not-working-correctly/
Your help would be greatly appreciated.
Thanks,
Chris