I have found the below code to enable viewing the author of a custom post type and it works perfectly for one custom post type. But I need it to work for 4 custom post types called: detox, recipes, movements, lifestyle.
function add_author_support_to_posts() {
add_post_type_support( 'your_custom_post_type', 'author' );
}
add_action( 'init', 'add_author_support_to_posts' );
What is the correct syntax to include all 4 custom post types?
I have found the below code to enable viewing the author of a custom post type and it works perfectly for one custom post type. But I need it to work for 4 custom post types called: detox, recipes, movements, lifestyle.
function add_author_support_to_posts() {
add_post_type_support( 'your_custom_post_type', 'author' );
}
add_action( 'init', 'add_author_support_to_posts' );
What is the correct syntax to include all 4 custom post types?
I would build a loop to pass all my cpt's into like so
function add_cpt_author_support( ) {
$post_types = array('detox', 'recipes', 'movements', 'lifestyle');
foreach ($post_types as $type) {
add_post_type_support($type, 'author');
}
}
add_action( 'init', 'add_cpt_author_support' );
One other thought though, why aren't you just declaring support for authors when you register your custom post types?
function add_author_support_to_posts() {
$args = array(
'public' => true,
'_builtin' => false
);
$output = 'names';
$post_types = get_post_types( $args, $output );
foreach ( $post_types as $post_type ) {
add_post_type_support( $post_type, 'author' );
}
}
add_action( 'init', 'add_author_support_to_posts' );
Getting all custom post types as array with get_post_types function. Then running a foreach loop and adding the author support to custom post types