Forum

Thread tagged as: Error, Blog

Blog runtime error for Cat

I'm using skip template to list other blog posts in that category

        <?php
        $categories = perch_blog_post_categories(perch_get('s'), array(
            'skip-template'=>true,


            ));

        if (count($categories)) {
        $cat_slugs = array();
        foreach($categories as $cat) {
        $cat_slugs[] = $cat['categorySlug'];
        }

        perch_blog_custom(array(
        'filter' => 'postSlug',
        'match' => 'neq',
        'value' => perch_get('s'),
        'category' => $cat_slugs,
        'sort-order'=>RAND,
        'count'=>3,
        'template'=>'blog/related.html',
        'section'=>'Recipes'

        ));


            }

    ?>

I'm now getting the error:

Array
(
    [type] => 2
    [message] => Invalid argument supplied for foreach()
    [file] => /var/sites/n/website.co.uk/public_html/perch/addons/apps/perch_blog/runtime.php
    [line] => 284
)

It's working fine on dev with the same files, so I don't know what's suddenly changed on the live site so it no longer works. The site is using Perch 2.4.9 and Blog 4.0.3 on both live and dev.

Many thanks

Sarah Evans

Sarah Evans 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Looks like the post has no categories. I'll add a check for that.

Drew McLellan said:

Looks like the post has no categories. I'll add a check for that.

Ah ok I'm glad it was something simple. Thanks Drew.