Fatal error WP_Query
-
Hello,
I put this simple code in a snippet.
I get an error that blocks the whole site. I can’t log in to the dashboard.
I need to log into the database and disable the database snippet.
Where is it wrong?/ The Query
$args = array( 'post_type' => 'post', ); $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; } echo '</ul>'; } else { echo '<h1>no posts found</h1>'; } /* Restore original Post Data */ wp_reset_postdata();
Log:
[05-Sep-2020 13:04:01 UTC] PHP Fatal error: Uncaught Error: Call to a member function get_queried_object_id() on null in /home/customer/www/xxxxxxxxx/public_html/wp-includes/query.php:60 Stack trace: #0 /home/customer/www/xxxxxxxxx/public_html/wp-includes/class-wp-query.php(4337): get_queried_object_id() #1 /home/customer/www/xxxxxxxxx/public_html/wp-includes/class-wp-query.php(4273): WP_Query->generate_postdata(Object(WP_Post)) #2 /home/customer/www/xxxxxxxxx/public_html/wp-includes/class-wp-query.php(3314): WP_Query->setup_postdata(Object(WP_Post)) #3 /home/customer/www/xxxxxxxxx/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()'d code(11): WP_Query->the_post() #4 /home/customer/www/xxxxxxxxx/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(446): eval() #5 /home/customer/www/xxxxxxxxx/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(534): execute_snippet('// The Query\r\n$...', 15) #6 /home/customer/www/xxxxxxxxx/public_html/wp-includes/class-wp-hook.php(287): execute_active in /home/customer/www/xxxxxxxxx/public_html/wp-includes/query.php on line 60 {excessive log entries redacted}
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Fatal error WP_Query’ is closed to new replies.