WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
small error notice in breadcrumbs l. 226 (13 posts)

  1. thomask
    Member
    Posted 2 years ago #

    there is a problem, when mixing CPT and taxonomies (like e.g. http://money.mediacentrum.cz/reference/?kraj=ustecky-kraj&produkt=&branze=chemicka-vyroba), it than throws
    Notice: Trying to get property of non-object in /var/www/vhosts/money.cz/httpdocs/wp-content/plugins/wordpress-seo/frontend/class-breadcrumbs.php on line 226

    Actually it is a wordpress bug (#20994, #18614, #19035), so it is up to you if you will make some workaround just for your breadcrumb plugin.

    I'm solving it on my site by filling $post_type_obj->labels->name on such pages. And i have noticed one other bug - you are using on that line 226

    $archive_title = $post_type_obj->labels->menu_name;

    IMO it would be much better to use "name" instead of "menu_name" label, as it is standard in whole WP installation, where the name of post_type is needed. And btw menu_name is optional (but it may be automaticaly filled by "name", i am not sure)

    http://wordpress.org/extend/plugins/wordpress-seo/

  2. thomask
    Member
    Posted 2 years ago #

    and btw get_post_type(); (line 221) on such pages returns FALSE, so the whole part after it does not work

  3. thomask
    Member
    Posted 2 years ago #

    but only when there is no matching post. Sorry for multiple posts

  4. thomask
    Member
    Posted 2 years ago #

    I have solved it by adding get_post_type() condition to line:

    if ( function_exists('is_post_type_archive') && is_post_type_archive() && get_post_type()) {

  5. thomask
    Member
    Posted 2 years ago #

    and one more - if a post do not have any category, this erro notice appears
    Notice: Undefined offset: 0 in /var/www/vhosts/money.cz/httpdocs/wp-content/plugins/wordpress-seo/frontend/class-breadcrumbs.php on line 175

    Notice: Trying to get property of non-object in /var/www/vhosts/money.cz/httpdocs/wp-content/plugins/wordpress-seo/frontend/class-breadcrumbs.php on line 175

  6. Alexander Gieg
    Member
    Posted 2 years ago #

    I've reworked parts of the function for other reasons, but incorporated your suggestions above in my version, and posted the Pastebin link here for Joost to evaluate and perhaps adopt it. Please check if this version of mine can help you. Maybe we can improve it so as to solve all the issues?

  7. thomask
    Member
    Posted 2 years ago #

    yes, the problem with line 226 seems solved, there is still problem with line 175 (in your version it is 189:

    Notice: Undefined offset: 0 in /var/www/vhosts/money.cz/httpdocs/wp-content/plugins/wordpress-seo/frontend/class-breadcrumbs.php on line 189

    Notice: Trying to get property of non-object in /var/www/vhosts/money.cz/httpdocs/wp-content/plugins/wordpress-seo/frontend/class-breadcrumbs.php on line 189)

    and if your would also implement this little improvement (http://wordpress.org/support/topic/plugin-wordpress-seo-by-yoast-tiny-feature-request-with-code-to-implement-breadcrumb-category-precedence?replies=1) - i would buy you a beer when you come to prague ;-)

  8. Alexander Gieg
    Member
    Posted 2 years ago #

    I think the easiest way to check what's going on is to add a line after the $terms = wp_get_object_terms( $post->ID, $main_tax ); one, containing var_dump ($post, $main_tax, $terms); then look at what appears after a page reload:

    $terms = wp_get_object_terms( $post->ID, $main_tax );
    var_dump ($post, $main_tax, $terms);
    if ( is_taxonomy_hierarchical($main_tax) && $terms[0]->parent != 0 ) {

    Post it here, okay?

  9. thomask
    Member
    Posted 2 years ago #

    as i wrote, problem is, that this particular article has no selected category, not even uncategorised (it is normaly not possible with WP), so $terms return blank array. So it should probably not happen to almost anyone, just from programming standards it would be wise to first check if $terms[0] exist then directly expect it does

    So the line 190 should be

    if ( is_taxonomy_hierarchical($main_tax) && isset($terms[0]) && $terms[0]->parent != 0 ) {

    P.S.: this is that var_dump

    object(stdClass)#4254 (25) {
      ["ID"]=>
      int(3657)
      ["post_author"]=>
      string(1) "3"
      ["post_date"]=>
      string(19) "2012-06-06 19:05:57"
      ["post_date_gmt"]=>
      string(19) "2012-06-06 17:05:57"
      ["post_content"]=>
      string(0) ""
      ["post_title"]=>
      string(73) "Školení účetního programu Money S3 pro začátečníky i pokročilé"
      ["post_excerpt"]=>
      string(0) ""
      ["post_status"]=>
      string(7) "publish"
      ["comment_status"]=>
      string(6) "closed"
      ["ping_status"]=>
      string(6) "closed"
      ["post_password"]=>
      string(0) ""
      ["post_name"]=>
      string(24) "terminy-skoleni-money-s3"
      ["to_ping"]=>
      string(0) ""
      ["pinged"]=>
      string(0) ""
      ["post_modified"]=>
      string(19) "2012-06-07 15:54:52"
      ["post_modified_gmt"]=>
      string(19) "2012-06-07 13:54:52"
      ["post_content_filtered"]=>
      string(0) ""
      ["post_parent"]=>
      int(0)
      ["guid"]=>
      string(36) "http://money.mediacentrum.cz/?p=3657"
      ["menu_order"]=>
      int(0)
      ["post_type"]=>
      string(4) "post"
      ["post_mime_type"]=>
      string(0) ""
      ["comment_count"]=>
      string(1) "0"
      ["ancestors"]=>
      array(0) {
      }
      ["filter"]=>
      string(3) "raw"
    }
    string(8) "category"
    array(0) {
    }
  10. Alexander Gieg
    Member
    Posted 2 years ago #

    I'd say testing for !empty($terms) or count($terms) > 0 would be better given that an empty array is an expected return value of wp_get_object_terms(). Given that there's such a test a few lines below, we can take advantage of that by moving it up. I've updated the Pastebin with a new version that does this, plus your filter idea from the other thread (with a changed name more similar to other WPSEO breadcrumb filters). Give it a try!

  11. thomask
    Member
    Posted 2 years ago #

    it works perfectly, even the new filter, thank you, i hope that yoast will implement it

  12. thomask
    Member
    Posted 2 years ago #

    one bug - error notice alex in your version (not in original) on line 222

    $breadcrumb_array[] = array( 'title' => $this->get_bc_title( $ancestor ), 'url' => get_permalink($ancestor), 'class' => '', 'type' => get_post_type($ancestor), 'ID' => (int) $ancestor->term_id );

    - $ancestor is ID, so $ancestor->term_id at the end should be just $ancestor

  13. Alexander Gieg
    Member
    Posted 2 years ago #

    Oops! Fixed and reuploaded. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic