WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 …

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!

share|improve this question
up vote 3 down vote accepted

get_the_terms() is probably returning false.

Do a print_r($event_type_term) to see what you have in it.

From: http://codex.wordpress.org/Function_Reference/get_the_terms

Array of term objects on success. False if no terms are found in the given taxonomy and a wp_error object if an invalid taxonomy is entered.

share|improve this answer
Ok, the thing is this only happens when adding a NEW custom-post. So for posts that do already have terms associated with it this doesn't happen. The problem is solved by adding this if ( !empty( $event_type_term ) ) – mathiregister Aug 2 '12 at 8:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.