Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created June 3, 2014 11:48
Show Gist options
  • Save tommcfarlin/d934562a8d427d73a86b to your computer and use it in GitHub Desktop.
Save tommcfarlin/d934562a8d427d73a86b to your computer and use it in GitHub Desktop.
[WordPress] A long (read: less-than-ideal) way to determine if the current post type exists in the options array of post types.
<?php
function post_type_is_supported() {
$post_types = get_option( 'acme-supported-post-types' );
$current_post_type = get_post_type( get_the_ID() );
$is_supported = false;
foreach ( $post_types as $post_type_key => $post_type_val ) {
if ( $current_post_type === $post_type_key ) {
$is_supported = true;
break;
}
}
return $is_supported;
}
<?php
function post_type_is_supported() {
return in_array( get_post_type( get_the_ID() ), array_keys( get_option( 'acme-supported-post-types' ) ) );
}
@dbernar1
Copy link

dbernar1 commented Jun 6, 2014

What's in $post_type_val?

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