Skip to content

Instantly share code, notes, and snippets.

@flyingwebie
Last active August 11, 2021 23:01
Show Gist options
  • Save flyingwebie/fcddc38b5fab71b67b671c310548130a to your computer and use it in GitHub Desktop.
Save flyingwebie/fcddc38b5fab71b67b671c310548130a to your computer and use it in GitHub Desktop.
Search conditional Results snippet for Oxygen builder that uses Oxygen's Conditions feature to show different content based on whether the search contains any results.
<?php
if (function_exists('oxygen_vsb_register_condition') ) {
global $oxy_condition_operators;
oxygen_vsb_register_condition('Has Results', array('options'=>array('true', 'false'), 'custom'=>false), array('=='), 'search_has_results_callback', 'Search');
function search_has_results_callback($value, $operator) {
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