Support » Plugin: WP Super Cache » Error 500 for portfolio items on first view

  • Resolved luminsol

    (@luminsol)


    Hi guys,

    Wondering if anyone has any ideas about an issue I’m experiencing with a site.

    The theme I’m using has a Portfolio feature. When trying to view a portfolio item on the first go (e.g. mysite.com/portfolio-item/item-1), I get an Internal Error 500. However, refreshing the page on the second go works as expected.

    Digging into the server logs I see:

    [STDERR] PHP Fatal error: Cannot use object of type WP_Query as array in /home/mysite/public_html/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 1293

    When I look up this line it appears to be in this function:

    function wp_cache_post_id() {
    	global $posts, $comment_post_ID, $post_ID;
    	// We try hard all options. More frequent first.
    	if ($post_ID > 0 ) return $post_ID;
    	if ($comment_post_ID > 0 )  return $comment_post_ID;
    	if (is_single() || is_page()) return $posts[0]->ID; // *** this is line 1293
    	if (isset( $_GET[ 'p' ] ) && $_GET['p'] > 0) return $_GET['p'];
    	if (isset( $_POST[ 'p' ] ) && $_POST['p'] > 0) return $_POST['p'];
    	return 0;
    }

    I suspect it’s trying to get the post id of this portfolio item, but somehow the posts variable contains a WP_Query object and not an array of them?

    Anyone know what I need to alter in the code to fix this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’ve run into this problem before. It was due to a collision between variables with a custom WP_Query in a template.

    I’d check the template in question for using $posts $comment_post_ID or $post_ID. If any of those exist, I’d change the scope of the variables to the theme in question. For example change $posts to something like $theme_name_posts.

    If this is a third-party theme that is getting updates, I’d advise setting up a child theme to solve this problem so you can continue to get theme updates without re-introducing this problem

    luminsol

    (@luminsol)

    Thanks Christian, I figured out the problem but forgot to update this post.

    Yes you were correct, it was the $posts variable being overwritten. I can’t believe how poorly written some of these third-party ‘premium’ themes are!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Error 500 for portfolio items on first view’ is closed to new replies.