Title: parse_query filter changed in 3.1 ?
Last modified: August 19, 2016

---

# parse_query filter changed in 3.1 ?

 *  [alex chousmith](https://wordpress.org/support/users/chousmith/)
 * (@chousmith)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/parse_query-filter-changed-in-31/)
 * in previous versions of WP (3.0.5), i had been able to list all Pages with a 
   given Page Template (meta_key _wp_page_template = “mytemplate.php”) by adding
   a filter to the “parse_query” . the following code in my theme’s functions.php
   made it so the link **/wp-admin/edit.php?s&post_type=page&mypagetemplate=mytemplate.
   php** showed the EDIT PAGES screen, listing only Pages where the _wp_page_template
   = “mytemplate.php”
 *     ```
       add_filter( 'parse_query', 'my_pagetemplate_filter' );
       function my_pagetemplate_filter( $query ) {
           global $pagenow;
           if ( is_admin() && $pagenow == 'edit.php' && isset( $_GET['post_type'] ) && isset( $_GET['post_type'] ) == 'page' && isset( $_GET['mypagetemplate'] ) && isset( $_GET['mypagetemplate'] ) == 'mytemplate.php' ) {
               $query->query_vars['orderby'] = 'meta_value';
               $query->query_vars['meta_key'] = '_wp_page_template';
               $query->query_vars['meta_value'] = 'mytemplate.php';
           }
       }
       ```
   
 * However, with the upgrade to 3.1, that no longer works, and the same link now
   just returns “No pages found.”
 * Can anyone provide insight as to what has changed on the $query level, if this
   is still possible with WP 3.1, or if I should just forget that it ever was possible?

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

 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/parse_query-filter-changed-in-31/#post-1934369)
 * It’s not your fault, i’ve just spent the last 30 minutes testing code and checking
   Trac for bug reports, it’s due to(as far as i can tell) the introduction of the
   new meta parameters, you need to replace the `meta_key` and `meta_value` args
   with `meta_query`..
 * However, the usage of `meta_query` isn’t clear and sent me in circles for a little
   while, i finally spotted what i was doing wrong, which was highlighted in this
   ticket.
    [http://core.trac.wordpress.org/ticket/16563](http://core.trac.wordpress.org/ticket/16563)
 * Remove your three `$query->query_vars` lines and replace them with..
 *     ```
       set_query_var( 'meta_query', array( array( 'key' => '_wp_page_template', 'value' => 'mytemplate.php' ) ) );
       set_query_var( 'orderby','meta_value' );
       ```
   
 * And your function should then work as it previously did.. 😉
 *  [jaisonn](https://wordpress.org/support/users/jaisonn/)
 * (@jaisonn)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/parse_query-filter-changed-in-31/#post-1934417)
 * Thanks, Mark. That worked like a charm.
 *  [BrenFM](https://wordpress.org/support/users/brenfm/)
 * (@brenfm)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/parse_query-filter-changed-in-31/#post-1934700)
 * Thanks (again) t31os! That was starting to seriously bake my bacon!
 *  [marymidori](https://wordpress.org/support/users/marymidori/)
 * (@marymidori)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/parse_query-filter-changed-in-31/#post-1934719)
 * Unfortunately this still returns no results.
 *  /wp-admin/edit.php?s&post_status=all&post_type=inuit-firms&action=-1&m=0&sortby_status
   =A&paged=1&mode=list&action2=-1
 * ATTEMPT ONE:
 *     ```
       add_filter( 'parse_query', 'status_filter' );
   
       function status_filter( $query ) {
         global $pagenow;
           if ($pagenow=='edit.php' &&
           			isset($_GET['post_type']) && $_GET['post_type']=='inuit-firms' &&
                   isset($_GET['sortby_status']) && !empty($_GET['sortby_status'])) {
               set_query_var( 'meta_query', array( array( 'key' => 'if_status', 'value' => $_GET['sortby_status']) ) );
           }
        }
       ```
   
 * ATTEMPT TWO:
 * Before I was using the following which had no problems.
 *     ```
       add_filter( 'request', 'status_request' );
       function status_request($request) {
           $current_url = substr( $GLOBALS['PHP_SELF'], -18);
           if (is_admin() && $current_url == '/wp-admin/edit.php' && isset($request['post_type']) && $request['post_type']=='inuit-firms' &&
           isset( $_GET['sortby_status'] ) && !empty( $_GET['sortby_status'] ) ) {
   
       	$request['meta_key']   = 'if_status';
       	$request['meta_value'] = $_GET['sortby_status'];
           }
           return $request;
       }
       ```
   
 * I tried this code as well but setting $request[‘meta_query’], but this also found
   no posts.
 * Any thoughts on what could be conflicting in this case?
 * Thanks
    Midori
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/parse_query-filter-changed-in-31/#post-1934720)
 * Try this instead..
 *     ```
       add_action( 'parse_query', 'status_filter' );
   
       function status_filter() {
   
       	global $pagenow, $post_type;
   
       	if( 'edit.php' != $pagenow || 'inuit-firms' != $post_type || !isset( $_GET['sortby_status'] ) )
       		return;
   
       	$meta_group = array(
       		'key' => 'if_status',
       		'value' => $_GET['sortby_status']
       	);
   
       	set_query_var( 'meta_query', array( $meta_group ) );
       }
       ```
   
 *  [marymidori](https://wordpress.org/support/users/marymidori/)
 * (@marymidori)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/parse_query-filter-changed-in-31/#post-1934721)
 * Unfortunately still finds no posts.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/parse_query-filter-changed-in-31/#post-1934722)
 * I’ve just tested the code for you and it works.
 * Check your spelling, are you requesting the page with..
 *     ```
       ?sortby_status=term
       ```
   
 * and not..
 *     ```
       sortbystatus=term
       ```
   
 * And is your field definately called `if_status` and not `if-status`
 * I can only guess it’s a small error in the naming somewhere(eg. a missing or 
   incorrect character), the code works for me.
 * Is your post type name definately correct?
    Is the meta key you’re requesting
   correct and definately applied to one of the custom post types?
 *  [marymidori](https://wordpress.org/support/users/marymidori/)
 * (@marymidori)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/parse_query-filter-changed-in-31/#post-1934723)
 * I do not what it could be. I use the following code to display the dropdown and
   it works, showing the correct value when selected:
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * I definitely have at least one post of each.
 * All to say, there could very easily be a naming error somewhere, but I have no
   idea where!
 * I’ll keep looking.
 * Thanks for your help,
    mido.
 *  [slobizman](https://wordpress.org/support/users/slobizman/)
 * (@slobizman)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/parse_query-filter-changed-in-31/#post-1934730)
 * I can’t believe this was changed on us like this. My now-not working code seems
   a little different than the above. Can someone he;lp me out as to what to change?
 * My Thesis function to omit some categories of posts from displaying.
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 *  [slobizman](https://wordpress.org/support/users/slobizman/)
 * (@slobizman)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/parse_query-filter-changed-in-31/#post-1934731)
 * I figured it out. I’ll post the change for anyone else:
 *     ```
       if ($query->is_home ) {
            $query->set('category__not_in', array(226,317));
          } elseif ($query->is_paged ) {
             $query->set('category__not_in', array(226,317));
          } elseif ($query->is_search ) {
             $query->set('category__not_in', array(226));
          } elseif ($query->is_archive ) {
             $query->set('category__not_in', array(226));
          } elseif ($query->is_feed ) {
             $query->set('category__not_in', array(226));
          }
          return $query;
       ```
   

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

The topic ‘parse_query filter changed in 3.1 ?’ is closed to new replies.

## Tags

 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [parse_query](https://wordpress.org/support/topic-tag/parse_query/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 10 replies
 * 6 participants
 * Last reply from: [slobizman](https://wordpress.org/support/users/slobizman/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/parse_query-filter-changed-in-31/#post-1934731)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
