Only apply to X post type
-
Is this the correct way to only show the mentioned post type and filter out anything else?
It seems to work fine as of now but sadly the other topic was closed.
In my example I’d like to only show test.
/**
* Restrict Post Type Switcher to only "test"
*/
add_filter( 'pts_get_post_types_filter', function ( $post_types ) {
$allowed = array( 'test' );
foreach ( $post_types as $post_type => $data ) {
if ( ! in_array( $post_type, $allowed, true ) ) {
unset( $post_types[ $post_type ] );
}
}
return $post_types;
} );
You must be logged in to reply to this topic.