Using WordPress’ pre_get_posts to filter query results

Wordpress

Post Type Search Filter

This is an example filter that will only get posts that are under a certain category of “State” that is posted through a $_GET in the URL.

So http://site.com/?q_state=ca will filter all posts that have the Category of “California” (‘ca’ is the slug)

function customize_customtaxonomy_archive_display ( $query ) {
    if (($query->is_main_query()) && (is_tax('review_category')) ) {

    $query->set( 'orderby', 'title' );
    $query->set( 'order', 'ASC' );

    // We will mess with this later    
    $query->set( 'posts_per_page', '-1' );

        if ( isset( $_GET['q_state'] ) && $_GET['q_state'] != "" ) {
            $query->set('state', $_GET['q_state'] );
        }
    }
}
//Hook the function
add_action( 'pre_get_posts', 'customize_customtaxonomy_archive_display' );