Saturday, November 19, 2022
HomeWordPress Developmentpages - PHP warning $post->ID is null

pages – PHP warning $post->ID is null


I have been having some issue with the next error, and my PHP expertise are fairly non-existent. Every time I attempt to create a brand new web page, I get the next error: PHP Warning: Try and learn property “ID” on null in … capabilities.php on line 1266 (additionally strains 1268 and 1271). This error maps to the usage of $post->ID.

operate autoset_featured() {
      international $submit;
      $already_has_thumb = has_post_thumbnail(**$post->ID**);
    if (!$already_has_thumb)  {
        $attached_image = get_children( "post_parent=**$post->ID**&post_type=attachment&post_mime_type=picture&numberposts=1" );
        if ($attached_image) {
            foreach ($attached_image as $attachment_id => $attachment) {
            set_post_thumbnail(**$post->ID**, $attachment_id);
            }
        }
    }
}

As I discussed, when including a brand new “web page,” an error seems, till a featured picture has been chosen. However when the web page is revealed, the picture would not present. And once I regulate Web page.php to show the picture when revealed, the error nonetheless exhibits.

I am probably not positive what to do at this level to resolve this error. Any concepts could be drastically appreciated. Thanks!

enter image description here

enter image description here

NOTE: Right here is my web page.php code. I wasn’t capable of finding the place web page.php was calling the operate…

    <?php
/**
 * Template for displaying all pages
 * @package deal WordPress
 * @subpackage Heidelbrew
 * @since Heidelbrew 1.0
 *
**/
get_header(); ?>

        <div id="major">
            <div id="content material" position="fundamental">

                <?php whereas ( have_posts() ) : the_post(); ?>

                    <?php get_template_part( 'content material', 'web page' ); ?>

                    <?php comments_template( '', true ); ?>

                <?php endwhile; // finish of the loop. ?>

            </div><!-- #content material -->
        </div><!-- #major -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Right here is the code for content-page.php that web page.php references

<?php
/**
 * Template used for displaying web page content material in web page.php
 * @package deal WordPress
 * @subpackage Heidelbrew
 * @since Heidelbrew 1.0
 */
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
        <h1 class="entry-title"><?php the_title(); ?></h1>
    </header><!-- .entry-header -->

    <div class="entry-content">
        <?php the_content(); ?>
        <?php wp_link_pages( array( 'earlier than' => '<div class="page-link"><span>' . __( 'Pages:', 'heidelbrew' ) . '</span>', 'after' => '</div>' ) ); ?>
    </div><!-- .entry-content -->
    <footer class="entry-meta">
        <?php edit_post_link( __( 'Edit', 'heidelbrew' ), '<span class="edit-link">', '</span>' ); ?>
    </footer><!-- .entry-meta -->
</article><!-- #post-<?php the_ID(); ?> -->

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments