- This topic has 3 replies, 2 voices, and was last updated 6 years, 8 months ago by
Tom.
-
AuthorPosts
-
July 18, 2019 at 12:30 pm #961436
Chris
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
July 18, 2019 at 5:58 pm #961562Tom
Lead DeveloperLead DeveloperHi there,
That looks like it should work.
Are we sure
$category_slugis outputting the correct text?July 19, 2019 at 2:00 am #961744Chris
Hi Tom,
Thanks for the reply.
As it happens, I fixed the problem late last night by running the exact same code in a PHP snippet plugin and then placing the snippet shortcode in the GP Hook.
However, when running the PHP directly in the GP Hook, it does not work. And yes,
$category_slugis outputting the correct value, as can be seen from the additionalechoI added for debug purposes after the shortcode. I also triedvar_dump($category_slug)and that gave the correct value.So, unresolved anomaly but a workaround has been found.
Thanks again for the reply.
Chris
July 19, 2019 at 9:48 am #962120Tom
Lead DeveloperLead DeveloperVery strange – it’s possible that GP Hooks is having a tough time running the variable inside
do_shortcode(). Have you tried a Hook Element? -
AuthorPosts
- You must be logged in to reply to this topic.