Skip to content

Instantly share code, notes, and snippets.

@whyisjake
Created May 31, 2013 23:31
Show Gist options
  • Save whyisjake/5688636 to your computer and use it in GitHub Desktop.
Save whyisjake/5688636 to your computer and use it in GitHub Desktop.
Looking for a way to filter posts out of the main loop in the admin if they have a certain taxonomy term associated with them.
<?php
/**
* Hide Maker Faire applications from past faires
*
* In the past, CS had a method for only selecting the current
* faire for applications. We want to do the same here, and prevent
* all applications from showing up in the edit screen.
*
* @global $query
*
*/
function mf_hide_faires( $query ) {
if ( is_admin() && $query->is_main_query() && 'mf_form' == get_post_type() ) {
//$query->set( 'faire', '-328' );
$tax_query = array(
array(
'taxonomy' => 'faire',
'field' => 'ID',
'terms' => 328,
'operator' => 'NOT IN',
)
);
$query->set( 'tax_query', $tax_query );
return $query;
}
}
add_action( 'pre_get_posts', 'mf_hide_faires' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment