Domanda

I'm Starting a WordPress website and I'm having a problem with some of my posts.

This issue is only affecting 2 out of 4 articles and after investigating I cannot think on a reason for that.

This error message appears right below comments section:

Notice: Undefined offset: 0 in /home/***/public_html/wp-includes/class-wp-query.php on line 3152

When I search for that line, I find this function:

enter image description here

I have search for this function in my WordPress code and I only found a few matches:

grep -r rewind_posts *
wp-content/themes/magazine/themify/themify-wp-filters.php:              rewind_posts();
wp-includes/class-wp-query.php:                 $this->rewind_posts();
wp-includes/class-wp-query.php: public function rewind_posts() {
wp-includes/feed-rdf.php:<?php rewind_posts(); while (have_posts()): the_post(); ?>
wp-includes/query.php:function rewind_posts() {
wp-includes/query.php:  $wp_query->rewind_posts();

Regarding these results, there are two different implementations of this rewind_post function in query.php and class-wp-query.php.

There are only two places where this function is invoked. I focus on the one related to the theme that is being used, themify-wp-filters.php, It is called from this function: function themify_404_template This does not say a lot, because I'm not viewing a 404 page.

I'm currently using Super Socializer plugin but I have not enabled the social commenting feature.

Any ideas?

È stato utile?

Soluzione

You're looking in WordPress core files for the cause of the PHP notice, which is a waste of time, as 1) I doubt you've found a new bug in WordPress, and 2) you don't want to modify WordPress core files to fix a theme or plugin issue, and 3) the error is caused by a theme or plugin and not WordPress core, but shows up in the PHP notice as pointing to core files.

And besides all that, it's a PHP notice. Not an error, not a fatal error, but a notice. All that means is "hey, look at me, you might want to fix me at some point, but I'm not an error." Read https://stackoverflow.com/questions/4624474/php-difference-between-notice-and-warning

NOTICE: It is a message for saying what you should do and what you should not do.

WARNING: It occurs at run time.But it do not interrupt Code execution.

ERROR: It also occurs at run time, but program execution is not continued it terminates.

So check in wp-config.php and turn off debug so you don't see the notices https://codex.wordpress.org/Debugging_in_WordPress Or check in php.ini of your hosting account; see https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display

To more effectively find the cause of an PHP error or notice, use Debug as linked above. But the simplest thing to do is deactivate all plugins and reactivate until you find the one that throws the notice. Then ask the plugin for help or look in their forums. Or, if a plugin is not the cause, switch to the default WordPress theme and see if the notice is in the error logs recorded by wp_debug.

Altri suggerimenti

I recently provided some analysis for the rewind_posts function.

>grep -r rewind_posts *
wp-content/themes/magazine/themify/themify-wp-filters.php:              rewind_posts();
wp-includes/class-wp-query.php:                 $this->rewind_posts();
wp-includes/class-wp-query.php: public function rewind_posts() {
wp-includes/feed-rdf.php:<?php rewind_posts(); while (have_posts()): the_post(); ?>
wp-includes/query.php:function rewind_posts() {
wp-includes/query.php:  $wp_query->rewind_posts();

Most likely the problem is not in the WordPress core, since WordPress superior engineers would not allow for such problems to occur.

From the experience, the theme developers may forget sometimes to be clan the code so you may expect the problem in :

wp-content/themes/magazine/themify/themify-wp-filters.php: 

Using the rewind_posts without checking for some conditions with if(). The theme should have this checkers depending what will try to rewind.

I don't have the code so I cannot say more. You may send this problem to the theme support.

For me, the solution was, calling the_post() before calling the_content().

I encountered the same notice and the cause was due to using wordpress while(have_posts) inside a single-{name}.php file. And the notice disappeared after removing the loop.

For removing the script, you must configure the wp-config.php as defined below.

define( 'WP_DEBUG', false );

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top