[英]How can I display custom posts as a sortable table with PHP for WordPress?
理想情況下,我正在嘗試使用插件來執行此操作,然后將表格分配給我可以在網站上的任何地方使用的簡碼。
這是我添加自定義帖子類型的通用代碼:
<?PHP
function create_post_type_customers(){
// Set UI labels for CPT
$labels = array(
'name' => __('Customers'),
'singular_name' => __('Customer'),
'menu_name' => __('Customers'),
'parent_item_colon' => __('All Customers'),
'all_items' => __('All Customers'),
'view_item' => __('View Customer'),
'add_new_item' => __('Add New Customer'),
'add_new' => __('Add New'),
'edit_item' => __('Edit Customer'),
'update_item' => __('Update Customer'),
'search_items' => __('Search Customers'),
'not_found' => __('Not Found'),
'not_found_in_trash' => __('Not Found in Trash'),
);
// CPT Options
$args = array(
'label' => __('customers'),
'description' => __('Freedom Search Customers'),
'labels' => $labels,
'supports' => array('title', 'editor', 'revisions', 'custom-fields'),
'taxonomies' => array('test'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'has_archive' => true,
'rewrite' => array('slug' => 'customers'),
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'show_in_rest' => true,
);
register_post_type('Customers', $args);
}
add_action('init', 'create_post_type_customers', 0);
?>
我對 PHP 和 WordPress 開發相當陌生,所以如果不是一個完整的解決方案,一些大方向會很棒。
注意- register_post_type('Customers', $args); 使客戶小寫
這是一個如何開始的簡單示例
// Call shortcode by echo do_shortcode('[customers]') or [customers]
add_shortcode( 'customers', 'customers_shortcode' );
function customers_shortcode() {
$args = array(
'post_type' => 'customers',
'posts_per_page' => -1,
'post_status' => 'publish',
'orderby' => 'DATE',
'order' => 'DESC',
);
$customers = new WP_Query($args);
if($customers->have_posts()):
while($customers->have_posts()): $customers->the_post();
//Do stuff here
the_title();
endwhile;
endif;
wp_reset_query();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.