Title: WP_Query does not fetch posts
Last modified: December 16, 2016

---

# WP_Query does not fetch posts

 *  [Expert1](https://wordpress.org/support/users/expert1/)
 * (@expert1)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/wp_query-does-not-fetch-posts/)
 * _[Moderator note: moved to How-To and Troubleshooting]_
 *     ```
       $line[0]="Santa's Wild Ride";
       $query = new WP_Query(array('post_type'=>'it_games',
       				'tax_query' => array(
       					array(
       						'taxonomy' => 'game_name',
       						'field'    => 'name',
       						'terms'    => stripslashes_deep($line[0])
       					)
       				)
       	));
       $id=0;
       if($query->have_posts()) $id=$query->post->ID;
       echo $id;
       ```
   
 * That code does not find posts. But I checked in admin panel there’s post with
   this term in this taxonomy.
 * I use exactly same code to find games which names don’t contain apostrophe and
   it works!
    But it also does not work for terms with symbols “(“, “)”. What am
   I doing wrong?
    -  This topic was modified 9 years, 6 months ago by [Expert1](https://wordpress.org/support/users/expert1/).
    -  This topic was modified 9 years, 6 months ago by [bdbrown](https://wordpress.org/support/users/bdbrown/).

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

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/wp_query-does-not-fetch-posts/#post-8562253)
 * You’ve done nothing wrong. It looks like you’ve stumbled upon a bug in WordPress
   core! The tax_query parser ends up double escaping name term arguments, so your
   term ends up being “Santa\\\’s Wild Ride” instead of the proper “Santa\’s Wild
   Ride”.
 * A workaround until this is fixed in core would be to add a filter to strip one
   set of slashes:
 *     ```
       // fix tax_query bug that double escapes name terms
       add_filter('pre_term_name', function( $term ) { return stripslashes( $term ); }, 40 );
       ```
   
 * You had the right idea to strip slashes, but doing it in the tax_query argument
   is too early, no slashes have been added at this point. (Unless your script potentially
   could be passing already escaped terms) I’m going to go ahead and file a Trac
   ticket since I have all the pertinent details, but I’ll certainly give you credit
   for finding the bug.
 * EDIT: The Trac ticket is [#39315](https://core.trac.wordpress.org/ticket/39315#ticket).
   You can click Watch this Ticket button to get email notifications when anyone
   posts a comment.
    -  This reply was modified 9 years, 5 months ago by [bcworkz](https://wordpress.org/support/users/bcworkz/).
      Reason: added Trac link
 *  Thread Starter [Expert1](https://wordpress.org/support/users/expert1/)
 * (@expert1)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/wp_query-does-not-fetch-posts/#post-8565005)
 * Thank you very much, it helped!
    But still does not work with symbols: (, ), [,]
   I tried addslashes($line[0]) in wp_query args, but still no luck.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/wp_query-does-not-fetch-posts/#post-8565916)
 * Hmmm, something else is going on then. Queries with ()[] work fine on my installation.
   They are unaffected by esc_sql(), addslashes(), etc., so the bug and my workaround
   would have no effect one way or another.
 * There must be some other code influencing your queries. You can try narrowing
   down the source by switching to a twenty* theme and deactivating all plugins,(
   the query should work now) then restoring each one by one until the query fails
   again.

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

The topic ‘WP_Query does not fetch posts’ is closed to new replies.

## Tags

 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/wp_query-does-not-fetch-posts/#post-8565916)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
