WordPress.org

Ready to get started?Download WordPress

Forums

Widget CSS Classes
PHP error: Trying to get property of non-object (9 posts)

  1. peterhebert
    Member
    Posted 7 months ago #

    When I have no published posts, the plugin produces the following PHP error in all widget areas:

    Notice: Trying to get property of non-object in /wp-includes/post-template.php on line 29

    Upon publishing a post, the notices go away. When I deactivate the plugin, no errors. I deactivated all other plugins, narrowed it down to this one. Same thing happens across multiple themes (tested with twenty fourteen and my custom theme).

    Having no posts is not a common scenario, of course, but the bug should be fixed nonetheless.

    http://wordpress.org/plugins/widget-css-classes/

  2. peterhebert
    Member
    Posted 7 months ago #

    Note that this notice appears once for every widget.

  3. spcaer
    Member
    Posted 6 months ago #

    I've noticed this problem as well on pages that don't have any posts returned; an example would be a search results page when no results are found.

    It looks like a check needs to be added to the following file/line to make sure a post ID exists before assigning the meta to the $custom_sidebarcheck variable.

    widget-css-classes\includes\widget-css-classes.class.php
    Line: 122

    Hopefully Cindy throws this check into a future version of the plugin. This is one of the most helpful plugins I've used, really nice work Cindy!!

  4. Cindy
    Member
    Plugin Author

    Posted 5 months ago #

    That is one testing scenario I did not do, so thank you for pointing it out. I will fix the notice.

  5. eddiegeis
    Member
    Posted 5 months ago #

    Having same problem on search result page with no posts to display. Thx for looking into this Cindy.

  6. Cindy
    Member
    Plugin Author

    Posted 5 months ago #

    This should be fixed in the version I just released (1.2.6)

  7. Keep2theCode
    Member
    Posted 4 months ago #

    Cindy, could you tell us what was causing this? I have a theme giving the same error message and haven't been able to track down the cause.

  8. Cindy
    Member
    Plugin Author

    Posted 4 months ago #

    I had to make sure there actually was a post ID before getting the value. This is the modified portion of the code:

    global $post;
    $id = ( isset( $post->ID ) ? get_the_ID() : NULL );
    if ( isset( $id ) && get_post_meta( $id, '_customize_sidebars' ) ) {
    $custom_sidebarcheck = get_post_meta( $id, '_customize_sidebars' );
    }
  9. Keep2theCode
    Member
    Posted 4 months ago #

    Thanks, Cindy. It turns out that "if $id = get_the_ID" is already after the error is caught, so I had to put "if have_posts" first and that took care of it.

Reply

You must log in to post.

About this Plugin

About this Topic