Skip to content

Instantly share code, notes, and snippets.

@wplit
Created August 1, 2019 23:42
Show Gist options
  • Select an option

  • Save wplit/f380710a33e08889f11f8ceccec9b75b to your computer and use it in GitHub Desktop.

Select an option

Save wplit/f380710a33e08889f11f8ceccec9b75b to your computer and use it in GitHub Desktop.
Is single post (of post type) condition
add_action('init', 'lit_register_condition_single_post_type');
function lit_register_condition_single_post_type() {
global $oxy_condition_operators;
$postTypes = get_post_types();
oxygen_vsb_register_condition('Single Post Type', array('options'=> array_keys($postTypes)), $oxy_condition_operators['simple'], 'lit_condition_single_post_type_callback', 'Post');
}
function lit_condition_single_post_type_callback($value, $operator) {
if($operator == '==') {
return ( is_singular($value) ) ? true : false;
}
else {
return ( !is_singular($value) ) ? true : false;
}
}
@quentin-th

Copy link
Copy Markdown

Hi and thanks for that snippet.

However, I would put it inside :

if( function_exists('oxygen_vsb_register_condition') ) {
    // snippet.php
} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment