1

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?

  • did you disable all your plugins? – funkysoul Jan 29 '17 at 16:07
  • 1
    A stack trace is required to try to understand the issue. the core reason for a problem is not always where the notice is emitted. – Mark Kaplun Jan 29 '17 at 17:21
  • Yes @funkysoul, I have disabled all plugins and the message is still there. Then, I have replaced my Themify theme with Twenty Seventeen and, voila, the NOTICE message has disappeared. So, it is definitely a theme issue. – WarioNeila86 Jan 29 '17 at 21:53
2

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.

  • 1
    If there is a php notice, than there is a bug in the code that emits the notice. Obviously the wp_query object is constructed badly, or was mutated in some unforeseen way, but if core can not guaranty the integrity of the object, it should check for the existence of the index in the array before accessing it, or/and give a better error. The OP had just done whatever debugging his knowledge/understanding made him think to be relevant, which is not enough, but it do not justify to call notices as non bugs.... – Mark Kaplun Jan 29 '17 at 17:15
  • 1
    Very good effort @markratledge I would add this link also: stackoverflow.com/questions/6549561/… – prosti Jan 29 '17 at 17:55
  • 1
    Thanks for your answer @markratledge, I really appreciate it. I didn't realise that I was facing a PHP error instead of a WordPress error. A newbie failure, I guess. Your suggestion about disabling DEBUG mode in wp-config.php has remembered me that I enabled this mode few days ago. So, maybe the NOTICE message has been always there but I did not see it before because DEBUG mode was disabled. I really thank you because you've made me understand a little better how WP works. Thanks. PS. I will try to find the root cause of this issue, but I'm glad I can hide it. – WarioNeila86 Jan 29 '17 at 21:46
  • 1
    @WarioNeila86, the WordPress code is PHP code. – prosti Jan 29 '17 at 22:12
0

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.

  • Hi @prosti, as I commented above, I have deleted all plugins and I've verified that this is a theme issue. I will contact Themify's support in case they can help. – WarioNeila86 Jan 29 '17 at 21:56
  • Yes, this is exactly wp-content/themes/magazine/themify/themify-wp-filters.php: where the problem is (in the theme) as I pointed out. @WarioNeila86 – prosti Jan 29 '17 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.