Cannot use object of type WP_Query as array SOLUTION
-
I found the issue someone had here https://www.ads-software.com/support/topic/bug-cannot-use-object-of-type-wp_query-as-array?replies=4, and on some other places. The issue happens because plugin has function:
/** * Detects post ID * * @return integer */ function w3_detect_post_id() { global $posts, $comment_post_ID, $post_ID; if ($post_ID) { return $post_ID; } elseif ($comment_post_ID) { return $comment_post_ID; } elseif (is_single() || is_page() && count($posts)) { return $posts[0]->ID; } elseif (isset($_REQUEST['p'])) { return (integer) $_REQUEST['p']; } return 0; }
And if you are on a custom page where you defined your query as
$posts= new WP_Query( $args );
Your object
$posts
will overwrite the global posts variable in the plugin and you’ll get this error.To get around this, just rename your query object to
$posts_myname
or similar and you won’t have any issues.Just thought that might help someone in the future ??
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Cannot use object of type WP_Query as array SOLUTION’ is closed to new replies.