[Support request] GP Hooks and List Category Posts shortcode

Home Forums Support GP Hooks and List Category Posts shortcode

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #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

    #961562
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    That looks like it should work.

    Are we sure $category_slug is outputting the correct text?

    #961744
    Chris

    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_slug is outputting the correct value, as can be seen from the additional echo I added for debug purposes after the shortcode. I also tried var_dump($category_slug) and that gave the correct value.

    So, unresolved anomaly but a workaround has been found.

    Thanks again for the reply.

    Chris

    #962120
    Tom
    Lead Developer
    Lead Developer

    Very strange – it’s possible that GP Hooks is having a tough time running the variable inside do_shortcode(). Have you tried a Hook Element?

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.