Created
May 5, 2021 10:34
-
-
Save KittenCodes/324d4ae4f71773035222ee15ed0ef94e to your computer and use it in GitHub Desktop.
Post Type Doesn't Contain Posts Condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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