在我的插件自定義後類型註冊
function register_cpt_gallery() {
$labels = array(
'name' => _x('Gallery', 'gallery'),
'singular_name' => _x('gallery', 'gallery'),
'add_new' => _x('Add New Album', 'gallery'),
'add_new_item' => _x('Add New Album', 'gallery'),
'edit_item' => _x('Edit gallery', 'gallery'),
'new_item' => _x('New Album', 'gallery'),
'view_item' => _x('View Album', 'gallery'),
'search_items' => _x('Search Album', 'gallery'),
'not_found' => _x('No Album found', 'gallery'),
'not_found_in_trash' => _x('No Album found in Trash', 'gallery'),
'parent_item_colon' => _x('Parent Album:', 'gallery'),
'menu_name' => _x('Gallery', 'gallery'),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Gallery filterable by genre',
'supports' => array('title', 'editor', '', 'thumbnail', '', '', '', '', ''),
'taxonomies' => array('genres'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-images-alt',
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type('gallery', $args);
}
add_action('init', 'register_cpt_gallery');
在php
頁
<?php $gallery_args = array(
'posts_per_page' => -1,
'orderby'=> 'date',
'order'=> 'DESC',
'post_type'=> 'gallery',
'post_status'=> 'publish',
'suppress_filters' => true
);
$posts_display_gallery = get_posts($gallery_args);
foreach($posts_display_gallery as $rows){
$post_title = $rows->post_title;
} ?>
你想獲得這個自定義後類型的所有帖子標題獲取
Post title
? –[get_posts](https://codex.wordpress.org/Function_Reference/get_posts)和[the_title](https://codex.wordpress.org/Function_Reference/the_title)? – vard
如果你有帖子ID,'get_the_title($ ID);'應該訣竅 –