Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In my <title> tags I am getting undefined on a custom taxonomy in a custom post type and im struggling to find a way to set it.

<title><br />
<b>Notice</b>:  Undefined property: stdClass::$labels in <b>/www/public_html/lib/wp-includes/general-template.php</b> on line <b>658</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>/www/public_html/lib/wp-includes/general-template.php</b> on line <b>658</b><br />
{custom_taxonomy_term} - {sitename}</title>

The URL called is: http://domain.com/{custom_post_type}/{custom_taxonomy}/{custom_taxonomy_term}/

The theme page serving it is: archive-{custom_post_type}.php

Its not getting the custom post type to me for the archive page so its firing a notice of it being blank. Not sure if there is a way I can force it or if I should be using a different theme page. Im using this to filter by taxonomies terms on custom post types.

The function in general-template.php is post_type_archive_title when applying filter post_type_archive_title to $post_type_obj->labels->name; which is the undefined part.

I would like the title to be something along the lines of {custom_term} - {custom_taxonomy} - {custom_post_type} - {sitename}.

Edit:

In the header.php I am using the usual <title><?php wp_title( '' ); ?></title> and have disabled Wordpress SEO plugin with same issue still.

Using custom rewrites on the taxonomy terms with rewrite => false on the register_taxonomy:

add_rewrite_rule( 
        '{custom_post_type}/{custom_taxonomy}/([^/]+)/?$',
        'index.php?post_type={custom_post_type}&{custom_taxonomy}=$matches[1]',
        'top');
share|improve this question
1  
Please provide the code you use to display the title for us to show, and what you already tried to solve the problem. –  Mike Madern Mar 18 '13 at 9:20
    
Added a bit more information which might help point to whats missing/going wrong. Thanks for the help. –  Jimbo Mar 18 '13 at 9:38
add comment

1 Answer

up vote 0 down vote accepted

I managed to fix this $labels undefined by writing the following work around. Its custom to how I wanted it to work but it may give others a pointer of how to get it to work for them. It occurs when Wordpress could use two types to serve its page and gets confused. Say if the page being served could be an archive page or a tag page (custom of course). Its not sure which way to serve the request and so the title gets knocked. So instead I tell it:

add_action( 'parse_query', 'my_custom_parse_query' );

function my_custom_parse_query( $wp_query ) { 
    global $post_type_obj;

    if ( $wp_query->is_post_type_archive && $wp_query->is_tax ) {

        $term = '';

        if( get_query_var('post_type') == 'my_post_type_1' ){

            $tax1 = get_query_var('custom_tax1');

            $tax2 = get_query_var('custom_tax2');

            $tax3 = get_query_var('custom_tax3');

            if(!empty($tax1)){

                $term = get_term_by( 'slug', $tax1, 'custom_tax1' );

            }else if(!empty($tax2)){

                $term = get_term_by( 'slug', $tax2, 'custom_tax2' );

            }else if(!empty($tax3)){

                $term = get_term_by( 'slug', $tax3, 'custom_tax3' );

            }

            if( !empty($term) ){

                $post_type_obj = get_queried_object();

            if (empty($post_type_obj->labels)) {
                $post_type_obj->labels = new stdClass();
                $post_type_obj->labels->name = $term->name . ' - ' . get_bloginfo('name');
            }

            }

        }else{

            $post_type_obj = get_queried_object();

        if (empty($post_type_obj->labels)) {
            $post_type_obj->labels = new stdClass();
            $post_type_obj->labels->name = $term->name;
        }

        }
    }
}
share|improve this answer
add comment

Your Answer

 
discard

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.