Last active
August 29, 2015 14:25
-
-
Save marushu/290354429c7e29330e53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* スライドショー投稿タイプ"スライドショー"を追加 | |
*/ | |
// Register Custom Post Type | |
function slider_type() { | |
$labels = array( | |
'name' => _x( 'スライドショー', 'Post Type General Name', 'textdomain' ), | |
'singular_name' => _x( 'スライドショー', 'Post Type Singular Name', 'textdomain' ), | |
'menu_name' => __( 'スライドショー', 'textdomain' ), | |
'name_admin_bar' => __( 'スライドショー', 'textdomain' ), | |
'parent_item_colon' => __( '親アイテム:', 'textdomain' ), | |
'all_items' => __( '全てのスライドショー', 'textdomain' ), | |
'add_new_item' => __( 'スライドショーを追加', 'textdomain' ), | |
'add_new' => __( 'スライドショーを新規追加', 'textdomain' ), | |
'new_item' => __( 'スライドショーを新規追加', 'textdomain' ), | |
'edit_item' => __( 'スライドショーを編集', 'textdomain' ), | |
'update_item' => __( 'スライドショーを更新', 'textdomain' ), | |
'view_item' => __( 'スライドショーを見る', 'textdomain' ), | |
'search_items' => __( 'スライドショーを検索', 'textdomain' ), | |
'not_found' => __( 'スライドショーは見つかりませんでした', 'textdomain' ), | |
'not_found_in_trash' => __( 'ゴミ箱にスライドショーは見つかりませんでした', 'textdomain' ), | |
); | |
$args = array( | |
'label' => __( 'slider', 'textdomain' ), | |
'description' => __( 'スライドショー', 'textdomain' ), | |
'labels' => $labels, | |
'supports' => array( ), | |
'taxonomies' => array( '' ), | |
'hierarchical' => false, | |
'public' => false, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'menu_position' => 5, | |
'show_in_admin_bar' => false, | |
'show_in_nav_menus' => false, | |
'can_export' => true, | |
'has_archive' => false, | |
'exclude_from_search' => true, | |
'publicly_queryable' => true, | |
'map_meta_cap' => true, | |
'capability_type' => 'page', | |
'capabilities' => array( | |
'create_posts' => false, | |
'delete_published_posts' => false, | |
), | |
); | |
register_post_type( 'slider', $args ); | |
} | |
add_action( 'init', 'slider_type', 0 ); | |
// スライドショー投稿タイプのみ1件追加する | |
$args = array( | |
'post_type' => 'slider', | |
); | |
$slider_posts = get_posts( $args ); | |
$slider_posts_count = count( $slider_posts ); | |
if( $slider_posts_count <= 0 ) { | |
$slider_post = array( | |
'post_title' => 'スライドショー', | |
'post_status' => 'publish', | |
'post_type' => 'slider', | |
'post_author' => 1, | |
'ping_status' => 'closed', | |
'comment_status' => 'closed', | |
); | |
$post_id = wp_insert_post( $slider_post ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment