[Support request] “PHP message: PHP Warning: Undefined variable $post

Home Forums Support [Support request] “PHP message: PHP Warning: Undefined variable $post

Home Forums Support “PHP message: PHP Warning: Undefined variable $post

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2239844
    Ravi Saive

    I am getting the following error in the nginx logs:

    2022/06/01 06:10:45 [error] 215858#0: *462115 FastCGI sent in stderr: "PHP message: PHP Warning: Undefined variable $post in /data/httpd/htdocs/tecmint/wp-content/plugins/gp-premium/elements/class-hooks.php(215) : eval()'d code on line 1PHP message: PHP Warning: Attempt to read property "ID" on null in /data/httpd/htdocs/tecmint/wp-content/plugins/gp-premium/elements/class-hooks.php(215) : eval()'d code on line 1" while reading response header from upstream, client: 141.101.99.153, server: tecmint.com, request: "GET /install-lxqt-desktop-in-ubuntu-fedora/ HTTP/2.0", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "www.tecmint.com", referrer: "https://www.tecmint.com/lightweight-linux-desktop-environments/"

    It seems the following Hook giving an error in the logs:

    If you have any questions or doubts? do <a style="text-decoration:underline;color:bb0e30;" href="<?php echo get_comments_link( $post->ID ); ?>">ask for help in the comments</a> section.

    #2239856
    Fernando
    Customer Support

    Hi Ravi,

    Can you try modifying the code to something like this?:

    If you have any questions or doubts? do <a style="text-decoration:underline;color:bb0e30;" href="<?php 
    	global $post;
    	echo get_comments_link( $post->ID ); 
    	?>">ask for help in the comments</a> section.

    Kindly let us know how it goes.

    #2240949
    Ravi Saive

    Hi @Fernando,

    The code worked fine, but I am getting another error as shown:

    2022/06/02 05:59:55 [error] 219688#0: *1065872 FastCGI sent in stderr: "PHP message: PHP Warning: Undefined array key 0 in /data/httpd/htdocs/tecmint/wp-content/plugins/gp-premium/elements/class-hooks.php(215) : eval()'d code on line 6PHP message: PHP Warning: Attempt to read property "slug" on null in /data/httpd/htdocs/tecmint/wp-content/plugins/gp-premium/elements/class-hooks.php(215) : eval()'d code on line 11" while reading response header from upstream, client: 141.101.99.25, server: tecmint.com, request: "GET /how-to-hack-your-own-linux-system/5-2/ HTTP/2.0", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "www.tecmint.com

    It seems the error coming from the following php code:

    <div class="wpsp-related-posts  grid-container">
    	<h2>Related Posts</h2>
    <?php
    if ( is_single() ) {
        $cats =  get_the_category();
        $cat = $cats[0];
    } else {
        $cat = get_category( get_query_var( 'cat' ) );
    }
    
    $cat_slug = $cat->slug;
    $list = get_page_by_title( 'related', 'OBJECT', 'wp_show_posts' );
    wpsp_display( $list->ID, 'tax_term="' . $cat_slug . '"' );
    ?>
    </div>
    #2240973
    Fernando
    Customer Support

    Where is this hook element displayed to?

    Is it being displayed in a post with no category? Or are you setting this to display on non-post pages?

    Kindly let us know.

    #2242041
    Ravi Saive

    I am displaying it on post pages which will show all related articles..

    #2242207
    Fernando
    Customer Support

    To have a better understanding of the issue, may you kindly provide the link to the site in question?

    You may use the private information field for this: https://docs.generatepress.com/article/using-the-premium-support-forum/#private-information

    Hope to hear from you soon. 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.