Title: Debugging PHP in VS Code issues
Last modified: March 31, 2020

---

# Debugging PHP in VS Code issues

 *  Resolved [GusGF](https://wordpress.org/support/users/gusgf/)
 * (@gusgf)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/debugging-php-in-vs-code-issues/)
 * I’m using Local by Flywheel to host locally my test site. I’ve run into a problem
   with a query in a php file that I’m getting nowhere with. So thought I’d resort
   to trying to using PHP debug for the first time. But I’ve come across a problem:
 * So in wp-config.php I set `define( 'WP_DEBUG', true );` Now when I reload my 
   page this message pops up….
 * Notice: is_main_query was called incorrectly. In pre_get_posts, use the WP_Query-
   >is_main_query() method, not the is_main_query() function. See [https://codex.wordpress.org/Function_R&#8230](https://codex.wordpress.org/Function_R&#8230);..
 * It doesn’t like this piece of code `if(!is_admin() && is_main_query() && is_post_type_archive('
   event')){`
 * But if I change it to `if(!is_admin() && WP_Query->is_main_query() && is_post_type_archive('
   event')){` I get a parse error!
 * If I set `define( 'WP_DEBUG', false );` the page loads without issue. What on
   earth is going on? How am I supposed to debug php.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/debugging-php-in-vs-code-issues/#post-12613059)
 * PHP notices usually do not affect normal operation, they just tell us we’re not
   doing something 100% right and it could become a problem. Some people ignore 
   notices, but being a responsible coder IMO means correcting all such transgressions.
   I recommend always developing with WP_DEBUG defined as `true`. Especially on 
   localhost installations. It decreases security some to leave it as `true` on 
   a production server.
 * What variable have you assigned the passed WP_Query object to? You need to use
   that object’s methods instead of global functions. Let’s say it’s `$query`. Then
   you need to do this:
    `if(! $query->is_admin() && $query->is_main_query() && 
   $query->is_post_type_archive('event')){`
 *  Thread Starter [GusGF](https://wordpress.org/support/users/gusgf/)
 * (@gusgf)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/debugging-php-in-vs-code-issues/#post-13338238)
 * Apologies for not responding and thank you for trying to help. Not sure how I
   resolved it in the end but I did.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Debugging PHP in VS Code issues’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 2 participants
 * Last reply from: [GusGF](https://wordpress.org/support/users/gusgf/)
 * Last activity: [5 years, 8 months ago](https://wordpress.org/support/topic/debugging-php-in-vs-code-issues/#post-13338238)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
