Skip to content

Instantly share code, notes, and snippets.

@KittenCodes
Created May 5, 2021 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KittenCodes/324d4ae4f71773035222ee15ed0ef94e to your computer and use it in GitHub Desktop.
Save KittenCodes/324d4ae4f71773035222ee15ed0ef94e to your computer and use it in GitHub Desktop.
Post Type Doesn't Contain Posts Condition
<?php
// Set your post type
$my_post_type = 'post';
if( function_exists('oxygen_vsb_register_condition') ) {
global $oxy_condition_operators;
oxygen_vsb_register_condition('Contains Posts', array('options'=>array('true', 'false'), 'custom'=>false), array('=='), 'search_has_results_callback', 'Query Has Posts');
function search_has_results_callback($value, $operator) {
$args = array(
'post_type'=> $my_post_type,
);
$thePosts = query_posts($args);
global $wp_query;
$posts_found = $wp_query->found_posts;
if( $value == "true" && $posts_found > 0) {
return true;
} else if( $value == "false" && $posts_found == 0 ) {
return true;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment