Reputation: 15
I have created custom post 'gallery' and now i want to add multiple gallery items. please help how i can do this. Here's my code
//Add custom post type for gallery
function cd_custom_post_gallery(){
register_post_type('gallery',
array(
'labels' => array(
'name' => __( 'Gallery' ),
'singular_name' => __( 'Gallery' ),
'all_items' => __( 'All Images'),
),
'taxonomies' => array(
'category',
),
'public' => true,
'has_archive'=>false,
'exclude_from_search' => true,
'rewrite' => array('slug' => 'gallery-item'),
'supports' => array( 'title', 'thumbnail' ),
'menu_position' => 9,
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'publicly_queryable' => false,
'query_var' => false
)
);
}
add_action('init', 'cd_custom_post_gallery');
function cd_get_featured_image($post_ID) {
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
if ($post_thumbnail_id) {
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'featured_preview');
return $post_thumbnail_img[0];
}
}
What i will add to add gallery items. Thanks in advance.
Upvotes: 0
Views: 5837
Reputation: 61
As mentioned in previous answers yes you can use ACF Plugin, but if you want to do this without using plugin, Make a custom post type Gallery. Then add custom meta field into it for uploading gallery items.
Another solutions is that you can use add media
option of wordpress post.
Upvotes: 2