Archived topic
"PHP message: PHP Warning: Undefined variable $post
5 replies · Started by Ravi Saive on May 31, 2022
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.
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.
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>
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.
I am displaying it on post pages which will show all related articles..
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. :)