Skip to content

Instantly share code, notes, and snippets.

@Clorith
Created March 3, 2014 09:52
Show Gist options
  • Save Clorith/9321698 to your computer and use it in GitHub Desktop.
Save Clorith/9321698 to your computer and use it in GitHub Desktop.
Quick filtering concept
<?php
$searcharg = array();
global $searcharg;
add_action( 'init', 'check_form' );
add_action( 'pre_get_posts', 'make_fancy_query' );
function check_form() {
if ( isset( $_GET['Checkme'] ) ) {
global $searcharg;
$searcharg = $_GET['Checkme'];
}
}
function make_fancy_query( $query ) {
global $searcharg;
if ( $query->is_main_query() && ! empty( $searcharg ) ) {
$query->set();
}
}
?>
<form action="" method="get">
<input type="text" name="s">
<input type="checkbox" name="Checkme" value="check1">
<input type="checkbox" name="Checkme" value="check2">
<input type="checkbox" name="Checkme" value="check3">
<input type="submit" value="Search">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment