Warning: array_pop() expects parameter 1 to be array, boolean given

Getting the following php error when trying to add a new post:

Warning: array_pop() expects parameter 1 to be array, boolean given in
/home/mysite/public_html/blog/wp-content/themes/mytheme/functions.php
on line 675

Here is the function:

function glossary_term_permalink($post_link, $post, $leavename, $sample) {
    if (false !== strpos($post_link, '%recipe_cat%')) {
        $glossary_letter = get_the_terms($post->ID, 'recipe_cat');
        $post_link = str_replace('%recipe_cat%', array_pop($glossary_letter)->slug, $post_link);
    }
    return $post_link;
}

Any idea what the issue is and how to resolve?

1 Answer
1

get_the_terms() will return a boolean false under some circumstances:

A post with no terms assigned gives a false result, not an empty
array.

https://codex.wordpress.org/Function_Reference/get_the_terms#Returns

It sounds like that is what is happening. You need to check that $post_link = to ensure that it is the type you expect before trying to use it.

Leave a Comment