• Warning: Undefined variable $post in /wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()'d code on line 6

    Warning: Attempt to read property "ID" on null in /wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()'d code on line 6


    Warning: Undefined variable $post in /wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()'d code on line 7

    Warning: Attempt to read property "ID" on null in /wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()'d code on line 7


    Warning: Undefined variable $post in /wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()'d code on line 8

    Warning: Attempt to read property "ID" on null in /wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()'d code on line 8


    Warning: Undefined variable $post in /wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()'d code on line 9

    Warning: Attempt to read property "ID" on null in /wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()'d code on line 9


    Warning: Undefined variable $post in /wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()'d code on line 10

    Warning: Attempt to read property "ID" on null in /wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()'d code on line 10
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support markomiljanovic

    (@markomiljanovic)

    Hi @rsalafy,

    Those warnings indicate that the issue is originating from one of your active code snippets during execution.

    If you can share the snippet, we can help identify the problem and suggest a solution.

    Thanks,
    Marko

    Thread Starter Mapan Web Indonesia

    (@rsalafy)

    I got no error messages when I first created the snippet weeks ago, only recently.

    Thread Starter Mapan Web Indonesia

    (@rsalafy)

    I added @ to suppress the error message

    Thread Starter Mapan Web Indonesia

    (@rsalafy)

    if ( function_exists('yoast_breadcrumb') ) {
    yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
    }

    echo '<table>';
    echo @the_terms( $post->ID, 'shipment-service', '<tr><th>Shipment Service</th><td>', ', ', '</td></tr>' ) . '<br />';
    echo @the_terms( $post->ID, 'shipment-status', '<tr><th>Shipment Status</th><td>', ', ', '</td></tr>' ) . '<br />';
    echo @the_terms( $post->ID, 'delivered-in', '<tr><th>Delivered in</th><td>', ', ', '</td></tr>' ) . '<br />';
    echo @the_terms( $post->ID, 'package-weight', '<tr><th>Package Weight</th><td>', ', ', '</td></tr>' ) . '<br />';
    echo @the_terms( $post->ID, 'amount', '<tr><th>Amount</th><td>', ', ', '</td></tr>' );
    echo '</table>';
    Plugin Support markomiljanovic

    (@markomiljanovic)

    HI @rsalafy,

    The errors were caused because the code snippet was trying to access the $post variable, which isn’t always available on every page or in every context of WordPress. When $post isn’t set, trying to use $post->ID results in warnings (like “Undefined variable” or “Attempt to read property ‘ID’ on null”).

    We suggest adding code to check if a post is actually available before using it.

    Here is the modified code snippet:

    global $post;

    if ( isset( $post ) && is_object( $post ) ) {
    if ( function_exists('yoast_breadcrumb') ) {
    yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
    }

    echo '<table>';
    the_terms( $post->ID, 'shipment-service', '<tr><th>Shipment Service</th><td>', ', ', '</td></tr>' );
    the_terms( $post->ID, 'shipment-status', '<tr><th>Shipment Status</th><td>', ', ', '</td></tr>' );
    the_terms( $post->ID, 'delivered-in', '<tr><th>Delivered in</th><td>', ', ', '</td></tr>' );
    the_terms( $post->ID, 'package-weight', '<tr><th>Package Weight</th><td>', ', ', '</td></tr>' );
    the_terms( $post->ID, 'amount', '<tr><th>Amount</th><td>', ', ', '</td></tr>' );
    echo '</table>';
    }
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Warning’ is closed to new replies.