WordPress.org

Forums

Breadcrumb NavXT
error in 5.1.0 update (12 posts)

  1. adilsaeed31
    Member
    Posted 1 year ago #

    HI Everyone,

    There is error in this plugin after updates to 5.1.0, below is error

    Catchable fatal error: Argument 1 passed to bcn_breadcrumb_trail::do_post() must be an instance of WP_Post, instance of stdClass given, called in /var/www/html/myhome/wp-content/plugins/breadcrumb-navxt/class.bcn_breadcrumb_trail.php on line 807 and defined in /var/www/html/myhome/wp-content/plugins/breadcrumb-navxt/class.bcn_breadcrumb_trail.php on line 358

    Please let me know if you guys are know how to solve it.

    Thanks

    Adil

    https://wordpress.org/plugins/breadcrumb-navxt/

  2. John Havlik
    Member
    Plugin Author

    Posted 1 year ago #

    What kind of post/page (or CPT) did you try visiting that exhibited this behavior? I'll need a little more information when I look I to this tonight.

  3. adilsaeed31
    Member
    Posted 1 year ago #

    Hi,

    The error comes on the articles page / custom made template page error in do_post function where you give the WP_Post $posts

    file class.bcn_breadcrumb_trail.php
    line number 807 & 358 where you declared the function with wp_post object and $post argument.

    Thanks

  4. glenarborart
    Member
    Posted 1 year ago #

    Hello,

    I'm also getting the same error:

    Catchable fatal error: Argument 1 passed to bcn_breadcrumb_trail::do_post() must be an instance of WP_Post, instance of stdClass given, called in /home/gaaa/public_html/wp-content/plugins/breadcrumb-navxt/class.bcn_breadcrumb_trail.php on line 807 and defined in /home/gaaa/public_html/wp-content/plugins/breadcrumb-navxt/class.bcn_breadcrumb_trail.php on line 358

  5. John Havlik
    Member
    Plugin Author

    Posted 1 year ago #

    @adilsaeed31: I know how to read the PHP error ;); I was wondering how you managed to have the $post global be a normal object rather than a WP_Post object. Additionally, it is interesting that Breadcrumb NavXT 5.0.1 worked for you, this indicates the $post in question looks like a WP_Post object but isn't.

    More feedback as to if this is a CPT or not, and how the CPT was setup would be helpful in debugging this. Additionally, if you could try placing var_dump($GLOBALS['post']); before the $this->do_post($GLOBALS['post']); call on line 807 and get me the results for the page that throws the error that would be helpful. I'm trying to reproduce this on my testbed but I'm not having any luck with my initial attempts.

  6. manuelayar
    Member
    Posted 1 year ago #

    I had the same problem and back to 5.0.1 and it worked

  7. kerryritter
    Member
    Posted 1 year ago #

    John,

    I too am experiencing this on a custom post type. Here is my var_dump:

    object(stdClass)#5759 (29) { ["ID"]=> int(0) ["post_status"]=> string(5) "draft" ["post_author"]=> int(0) ["post_parent"]=> int(0) ["post_type"]=> string(4) "page" ["post_date"]=> int(0) ["post_date_gmt"]=> int(0) ["post_modified"]=> int(0) ["post_modified_gmt"]=> int(0) ["post_content"]=> string(0) "" ["post_title"]=> string(0) "" ["post_excerpt"]=> string(0) "" ["post_content_filtered"]=> string(0) "" ["post_mime_type"]=> string(0) "" ["post_password"]=> string(0) "" ["post_name"]=> string(0) "" ["guid"]=> string(0) "" ["menu_order"]=> int(0) ["pinged"]=> string(0) "" ["to_ping"]=> string(0) "" ["ping_status"]=> string(0) "" ["comment_status"]=> string(6) "closed" ["comment_count"]=> int(0) ["is_404"]=> bool(false) ["is_page"]=> bool(false) ["is_single"]=> bool(false) ["is_archive"]=> bool(false) ["is_tax"]=> bool(false) ["filter"]=> string(3) "raw" } object(stdClass)#5759 (29) { ["ID"]=> int(0) ["post_status"]=> string(5) "draft" ["post_author"]=> int(0) ["post_parent"]=> int(0) ["post_type"]=> string(4) "page" ["post_date"]=> int(0) ["post_date_gmt"]=> int(0) ["post_modified"]=> int(0) ["post_modified_gmt"]=> int(0) ["post_content"]=> string(0) "" ["post_title"]=> string(0) "" ["post_excerpt"]=> string(0) "" ["post_content_filtered"]=> string(0) "" ["post_mime_type"]=> string(0) "" ["post_password"]=> string(0) "" ["post_name"]=> string(0) "" ["guid"]=> string(0) "" ["menu_order"]=> int(0) ["pinged"]=> string(0) "" ["to_ping"]=> string(0) "" ["ping_status"]=> string(0) "" ["comment_status"]=> string(6) "closed" ["comment_count"]=> int(0) ["is_404"]=> bool(false) ["is_page"]=> bool(false) ["is_single"]=> bool(false) ["is_archive"]=> bool(false) ["is_tax"]=> bool(false) ["filter"]=> string(3) "raw" }

    To fix this, I updated these lines (Line 358 on class.bcn_breadcrumb_trail.php):

    protected function do_post(WP_Post $post)
    {

    and changes to:

    protected function do_post($post)
    {
    if (get_class($post) != "WP_Post") return;

    This resolved issues for me.

  8. John Havlik
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for the var_dump. The question is why is the global $post a stdClass that looks similar to a WP_Post object? I have not been able to reproduce this issue on any of my testbeds by simply visiting a custom post type post instance or archive. Is there anything else in this setup? Any other plugins in use? Any widgets? Anything else modifying the $post global?

  9. KoZm0kNoT
    Member
    Posted 1 year ago #

    I am having this issue on my site with custom post types. BUT, I have some caveats....it's ONLY on new posts I create and only on one certain page where I list all my posts. Breadcrumbs work perfectly when I display the individual post, even on the new ones. I have a sneaky suspicion there is a bug on this one particular page and the WP_Post object is not getting cast properly (hence the error about it not being a WP_Post object, which it clearly is.) I didn't write the code on the page with the problem - it was part of a package I purchased - so I'll need to debug it. As soon as I figure out what's going on I'll post the results and hopefully it may help others. Since it worked in earlier versions, there might have been some sloppy code floating around that a lot of people found on google and used that now won't work in the newer, cleaner versions of Breadcrumb. But that still doesn't explain why only new posts don't work on this one page.

  10. KoZm0kNoT
    Member
    Posted 1 year ago #

    Ok I have some additional details now. The page I'm having issues on simply displays a list of CPT posts. I use Microsoft WebMatrix on Windows 8.1 for my development work, then Filezilla the changes to a production hosted Apache server. The two environments are behaving differently. The WebMatrix side works as expected - the breadcrumb displays the name of the PAGE, as I want it. However, on the Apache server, it uses the last CPT POST on the page in the breadcrumb...not the page itself. For some reason, there seems to be some sort of delay...breadcrumb is not grabbing the page name at the top but waits until the whole page is displayed before getting the current $POST value to put in the breadcrumb.

    This is related to the WP_POST object error because for some reason before I upgraded breadcrumb, it did not exhibit this behavior. Also, something has changed in WP in the way new posts are created since old CPT posts do not break breadcrumbs.

  11. KoZm0kNoT
    Member
    Posted 1 year ago #

    Got it figured out. I have a shortcode function that creates a list of CPT posts. This code executes prior to the template page that actually displays the content. The content is "queued up" using the PHP "ob_start" and finishes with "ob_end_clean", then this content is passed on to the page. This function gets its list of CPT posts using a WP_Query, so the $POST gets used during this process.

    In the page that displays the list CPT posts, I had the breadcrumb statement "bcn_display()" BEFORE I executed the "the_post()" function, so breadcrumb was trying to use the LAST CPT post from the shortcode function instead of the WP_Post object of my page. Once I moved my breadcrumb command AFTER "the_post", then it had the correct WP_POST object and fixed the issue. Here is how it looked before and after:

    BEFORE:

    <?php
    	get_header();
    ?>
    	<div class="breadcrumb-wrap"><?php bcn_display();?></div>
    <?php
    	if ( have_posts() ) {
    		while ( have_posts() ) {
    			the_post();

    AFTER:

    <?php
    	get_header();
    
    	if ( have_posts() ) {
    		while ( have_posts() ) {
    			the_post();
    ?>
    	<div class="breadcrumb-wrap"><?php bcn_display();?></div>

    So if you are running queries prior to displaying the results, make sure you have your page WP_Post before calling breadcrumb.

  12. John Havlik
    Member
    Plugin Author

    Posted 1 year ago #

    Custom WP_Query instantiations/calls don't necessarily modify or change the contents of the $post global. In fact, $post is not touched by custom WP_Query statements unless your instantiation of WP_Query is assigned to $post, which you probably should not do. Also, if you are modifying $post for a custom loop, you should restore it to it's original state after exiting that loop.

    Also, for your shortcode, is there a reason you're using the ob_* functions? Most of loop functions that normally echo content have equivalents that return strings (typically same function name prefixed with get_).

    Anyways, thanks for the additional detail. If similar things are causing this problem for others, then it's a long know behavior of Breadcrumb NavXT. It is assumed that other code does not mess with the $post global for Breadcrumb NavXT to behave correctly. While code could be added to try to correct for corrupted $post globals it causes problems with running within the loop and in the cases where the $post global is being modified for a legitimate reason (and you want Breadcrumb NavXT to follow that new $post).

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Breadcrumb NavXT
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.