array_pop() expects array, boolean given for $event_type_term ->slug

I have the following function I wrote …

add_filter('post_type_link', 'events_permalink_structure', 10, 4);

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

When creating a new post I get the following Warnings in the backend …

Read More

Warning: array_pop() expects parameter 1 to be array, boolean given in
/Users/my/htdocs/wr/wp-content/themes/wr/functions.php on line 168

Notice: Trying to get property of non-object in
/Users/my/htdocs/wr/wp-content/themes/wr/functions.php on line 168

Any ideas what I’m doing wrong here?

Thank you in advance!

Related posts

Leave a Reply

1 comment