I want to add post formats for each post type. For example, I have a post type ‘Gallery’. I want to add ‘images’, ‘galleries’ and ‘videos’ in this post. In normal posts I want to use another list of post formats.
I try:
function postf()
{
global $post_ID;
$postType = get_post_type( $post_ID );
if( $_GET['post_type'] || $postType == 'gallery-custompost' )
{
add_theme_support( 'post-formats', array( 'image', 'gallery', 'video' ) );
add_post_type_support( 'gallery-custompost', 'post-formats' );
}
}
add_action('init', 'postf');
When I add a new post, it works, but when I try to edit it, the post format does not appear.
Does anyone have any idea how I must do it?
Try adding the post format support on the arguments when you register your post type instead of using
add_post_type_support
, like this for example:See if have any luck.
You can change the list that appears in the post format meta box, but when you save the post the submitted value is checked against the registered post formats, and your code probably did not run there.
My solution is to register all post formats that you will use with your theme, and then limit them based on the post type by replacing the standard meta box with one of your own. This will only limit the available options in the meta box, it won’t restrict them when you save a post, but you can probably add extra checking to prevent adventurous users from setting “disallowed” post formats.
Post Formats are a custom taxonomy, registered for the “Post” post-type. If you want to use the “Post Format” taxonomy for a different post-type, then you’ll need to register it for that post-type, rather than merely enable support for it for the “Post” post-type.