Joseph Morgan
Published in : 2022-01-30
Hello everyone, I am facing weird error in my website I can see this error
Warning: Undefined variable $post in /customers/2/5/e/mastratec.com/httpd.www/wp-content/themes/salient-child/skills-section.php on line 21Warning: Attempt to read property "ID" on null in /customers/2/5/e/mastratec.com/httpd.www/wp-content/themes/salient-child/skills-section.php on line 21
the file looks like
<?php $args = ['post_type' => 'skills','status' => 'published','orderby' => 'date', 'order' => 'ASC','posts_per_page' => -1,];$count = 0;$posts = new WP_Query( $args );if( $posts->have_posts() ) :?> <div ><?php $count = 1 ;while($posts->have_posts()):$posts->the_post();?><div > <div > <?php if(get_the_post_thumbnail_url($post->ID)){ ?> <img src="<?php echo get_the_post_thumbnail_url($post->ID); ?>" alt="Image"> <?php } ?> <div > <h4><?php the_title(); ?></h4> </div> </div></div><?phpif($count % 6 == 0){echo "</div> <div class='skills_container'>";}$count++ ;endwhile;else:echo "<h3 style='text-align: center;'> No posts to show </h3>";endif;?>
This is the first time to see this error however that code is working fine on another server,
Please help
Join our community and get the chance to solve your code issues & share your opinion with us
Sign up Now
Mohamed Atef Date : 2022-01-30
Best answers
51
Best answers
51
Hi Joseph,
This might be a error because of a different PHP version or any Wordpress update, but anyway I got the issue & there are a simple way to figure this out,
You can figure this error by replacing $post->ID with a function to get the ID of the post inside the loop which is get_the_ID()
Your loop should looks like
Good luck!!
Joseph Morgan Date : 2022-01-30
Thank you so much! you are amazing