I wrote a plugin Premium Posts that registers a custom taxonomy called sms_premium_posts and adds a column to the post list table in the WordPress administration area.
In that custom column, if a post has been marked Premium, the term Premium links to a filtered list of only premium posts. This link is generated using the query string:
http://www.example.com/wp-admin/edit.php?sms_premium_posts=premium
If a post is not marked as Premium, I would like the term Standard to filter the list so the table only shows posts that are NOT marked as premium (i.e. posts with no taxonomy terms).
Is there a query string for that?
Example query string:
http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium
You may ask, "Why not add the term Standard to all other posts?" My reason for not doing that is, it would require tagging all existing posts with a custom taxonomy term when the plugin is activated...which seems pretty inefficient.
Thanks in advance!
SOLUTION
Based on the answer from @s_ha_dum below, here is what I did to fake a negative query string:
function standard_term_filter( $query ) {
if ( ! $query->is_admin || ! isset( $_GET['sms_premium_posts!'] ) )
return $query;
if ( 'premium' == $_GET['sms_premium_posts!'] ) {
$taxquery = array(
array(
'taxonomy' => 'sms_premium_posts',
'field' => 'slug',
'terms' => 'premium',
'operator' => 'NOT IN'
)
);
$query->set( 'tax_query', $taxquery );
}
return $query;
}
add_action( 'pre_get_posts', array( $this, 'standard_term_filter' ) );
Note that I added this function as a method of my plugin class, which is why I used an array for the callback in add_action().
Also note the ! at the end of my query string term: sms_premium_posts!
I made my Standard term links look like this:
http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium
Since sms_premium_posts! is different than sms_premium_posts (the slug of my custom taxonomy), it works.