Title: PHP Warning errors in log
Last modified: September 20, 2024

---

# PHP Warning errors in log

 *  Resolved [Lukasz](https://wordpress.org/support/users/wpfed/)
 * (@wpfed)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/php-warning-errors-in-log/)
 * Two errors I have logged, if you can look into it:
   PHP Warning:  Attempt to read
   property “childNodes” on null in \wp-content\plugins\wordpress-popular-posts\
   src\Output.php on line 181
 * PHP Warning:  foreach() argument must be of type array|object, null given in \
   wp-content\plugins\wordpress-popular-posts\src\Output.php on line 181

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/php-warning-errors-in-log/#post-18027570)
 * Hey [@wpfed](https://wordpress.org/support/users/wpfed/),
 * Someone else reported this PHP warning some time ago (see [link](https://wordpress.org/support/topic/foreach-receiving-null-values-in-getoutput-method-of-output-php/)).
   I couldn’t reproduce the problem back then and the reporter didn’t provide any
   further details (otherwise I would have probably fixed it by now.)
 * Could you please share reproduction steps? (As in, how are you using the plugin,
   settings, etc.)
    -  This reply was modified 1 year, 8 months ago by [Hector Cabrera](https://wordpress.org/support/users/hcabrera/).
      Reason: Fixed a couple of typos
    -  This reply was modified 1 year, 8 months ago by [Hector Cabrera](https://wordpress.org/support/users/hcabrera/).
      Reason: Added link to previous report
 *  Thread Starter [Lukasz](https://wordpress.org/support/users/wpfed/)
 * (@wpfed)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/php-warning-errors-in-log/#post-18028541)
 * Hey [@hcabrera](https://wordpress.org/support/users/hcabrera/),
 * Interesting, I will have a look at the thread in greater details and share reproduction
   steps.
 *  Thread Starter [Lukasz](https://wordpress.org/support/users/wpfed/)
 * (@wpfed)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/php-warning-errors-in-log/#post-18028614)
 * This appears to happen when there is no popular posts in certain categories, 
   for example I have pages with associated categories, the category for the page
   is returned and then wpp checks for any posts in that category and passes null
   to the output which is then attempted to be processed. I’ll try to see if I an
   add some error handling for this situation.
   This is from my page.php:
 *     ```wp-block-code
       global $post;                    if ( is_page( $post->ID ) && ! is_page( $contactUsPage ) ) {                        $helpfulArticles = esc_html__( 'You might also find these helpful.', 'domain' );                        $key_name = get_post_custom_values( $key = 'cat' );                        $cat_ID   = get_cat_ID( $key_name[0] );                        if ( function_exists( 'pll_register_string' ) ) {                            $currentID = pll_get_post( 300 );                        }                        $closerForAside = '<li><a href="' . esc_url( get_permalink( $currentID ) ) .                            '">'                            . esc_html__( 'See all Articles', 'domain' ) . '<i class="fa fa-angle-right" aria-hidden="true"></i></a></li></ul></section></div>';                        $args = array(                            'post_type'   => 'post',                            'limit'       => 3,                            'cat'         => pll_get_term( $cat_ID, 'en' ),                            'stats_views' => 0,                            'range'       => 'all',                            'freshness'   => 1,                            'wpp_start'   => '<div id="popularPosts" class="sidebar popularPosts" aria-labelledby="helpfulArticles">                <section class="sidebarHelpTopics"><h2 id="helpfulArticles">' . $helpfulArticles . '</h2><ul>',                            'wpp_end'     => $closerForAside,                        );                        wpp_get_mostpopular( $args );                    }
       ```
   
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/php-warning-errors-in-log/#post-18028686)
 * Thanks! I’ll give that code you shared a try sometime later today and see if 
   I can trigger that PHP warning. I’ll keep you posted.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/php-warning-errors-in-log/#post-18029914)
 * Quick update: tested the code, no PHP warnings at all. I modified it a bit though,
   removed all **pll_** calls since I don’t think that the warning is related to
   Polylang.
 * Could you please try this version of your code and see if you still see that 
   PHP warning?
 *     ```wp-block-code
       $helpfulArticles = esc_html__( 'You might also find these helpful.', 'domain' );$cat_ID   = 1; // Replace this category ID with one from your site$closerForAside = '<li><a href="' . esc_url( get_permalink() ) .    '">'    . esc_html__( 'See all Articles', 'domain' ) . '<i class="fa fa-angle-right" aria-hidden="true"></i></a></li></ul></section></div>';$args = array(    'post_type'   => 'post',    'limit'       => 3,    'cat'         => $cat_ID,    'stats_views' => 0,    'range'       => 'all',    'freshness'   => 1,    'wpp_start'   => '<div id="popularPosts" class="sidebar popularPosts" aria-labelledby="helpfulArticles"><section class="sidebarHelpTopics"><h2 id="helpfulArticles">' . $helpfulArticles . '</h2><ul>',    'wpp_end'     => $closerForAside,);wpp_get_mostpopular( $args );
       ```
   
 *  Thread Starter [Lukasz](https://wordpress.org/support/users/wpfed/)
 * (@wpfed)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/php-warning-errors-in-log/#post-18031410)
 * [@hcabrera](https://wordpress.org/support/users/hcabrera/) thanks for getting
   back. I copied in your code and just changed to one of the my categories which
   does not have any popular posts and received the exact same errors as before.
   As soon as I add a view to one of the posts in the category, the error disappears,
   so it’s only posts with empty views that throw the error, this wont really be
   issue in prod.
   But, I tried your code on my functions.php, and it worked, no 
   error, just blank if their is no views and link if their is views. So could it
   be a timing issue on page.php, maybe the function should be called within a hook
   or something to fire at the right time? This may not be sufficient:
 *     ```wp-block-code
       global $post;if ( is_page( $post->ID ) && ! is_page( $contactUsPage ) ) {
       ```
   
 * Edit: The is_page doesn’t make a difference, removed or not. Something to do 
   with outputting the results on page.php.
    -  This reply was modified 1 year, 8 months ago by [Lukasz](https://wordpress.org/support/users/wpfed/).
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/php-warning-errors-in-log/#post-18031522)
 * The one thing that caught my attention from what you said is that you’re getting
   a blank output when there are no posts. That should not be the case, you should
   be seeing a “Sorry, no data so far” text when WPP can’t find any popular posts
   🤔
 * I’m thinking I could provide you with a version of the plugin with some logging
   enabled so we can hopefully see what is actually happening when the plugin can’t
   find posts on your site. If you’re OK with that please use [my contact form](https://cabrerahector.com/about/#say-hi)
   and I’ll get back to you as soon as I can.
 *  Thread Starter [Lukasz](https://wordpress.org/support/users/wpfed/)
 * (@wpfed)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/php-warning-errors-in-log/#post-18031527)
 * Found the issue! – when I disable this filter, the error goes away, it seems 
   null is being passed from this function when no views found
 *     ```wp-block-code
       function my_custom_no_posts_found( $no_data_html ) {	//$output = '<style type="text/css">.popular-posts { display:none; }</style>';	$output = '';	return $output;}add_filter( 'wpp_no_data', 'my_custom_no_posts_found', 10, 1 );
       ```
   
 * I think I will just set .wpp-no-data as display none, to get the desired output.
 * Phew, thank you for your time on this, very much appreciated!
    -  This reply was modified 1 year, 8 months ago by [Lukasz](https://wordpress.org/support/users/wpfed/).
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/php-warning-errors-in-log/#post-18031787)
 * Oh, I was thinking that it _might_ be related to that filter but wasn’t sure.
   Great finding! I was able to replicate that PHP warning now, everything makes
   sense.
 * Alright, I’ll patch that up in the next version so you can have that filter hook
   return that empty string without triggering a PHP warning. Thank you for sharing
   this.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘PHP Warning errors in log’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-popular-posts/assets/icon-256x256.png?rev=1232659)
 * [WP Popular Posts](https://wordpress.org/plugins/wordpress-popular-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-popular-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-popular-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-popular-posts/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * Last activity: [1 year, 8 months ago](https://wordpress.org/support/topic/php-warning-errors-in-log/#post-18031787)
 * Status: resolved