Saya sudah bisa menyelesaikan ini sendiri. Seluruh kode saya untuk mendaftarkan CPT:
<?php
add_action( 'init', 'events_post_type_register' );
function events_post_type_register() {
$post_type = "events";
$labels = array(
'name' => _x('Events', 'post type general name', 'project_X'),
'singular_name' => _x('Event', 'post type singular name', 'project_X'),
'add_new' => _x('Add New', 'event', 'project_X'),
'add_new_item' => __('Add New Event', 'project_X'),
'edit_item' => __('Edit Event', 'project_X'),
'new_item' => __('New Event', 'project_X'),
'all_items' => __('All Events', 'project_X'),
'view_item' => __('View Event', 'project_X'),
'search_items' => __('Search Events', 'project_X'),
'not_found' => __('No events found', 'project_X'),
'not_found_in_trash' => __('No events found in trash', 'project_X'),
'parent_item_colon' => '',
'menu_name' => 'Events'
);
$args = array(
'labels' => $labels,
'public' => true,
'hierarchical' => false,
'has_archive' => true,
'rewrite' => array(
'with_front' => false,
'slug' => "news/{$post_type}"
),
'supports' => array( 'title', 'editor', 'thumbnail' )
);
register_post_type($post_type, $args);
remove_action("future_{$post_type}", '_future_post_hook');
add_action("future_{$post_type}", 'sc_ps_publish_future_events_now', 2, 10);
}
function sc_ps_publish_future_events_now($depreciated, $post) {
wp_publish_post($post);
}
add_filter('posts_where', 'sc_ps_show_future_events_where', 2, 10);
function sc_ps_show_future_events_where($where, $that) {
global $wpdb;
if("events" == $that->query_vars['post_type'] && is_archive())
$where = str_replace( "{$wpdb->posts}.post_status = 'publish'", "{$wpdb->posts}.post_status = 'publish' OR $wpdb->posts.post_status = 'future'", $where);
return $where;
}
?>
Jadi, agar posting dapat dilihat oleh semua pengguna, bahkan jika diatur di masa mendatang, Anda harus melakukan hal berikut:
remove_action("future_{$post_type}", '_future_post_hook');
add_action("future_{$post_type}", 'sc_ps_publish_future_events_now', 2, 10);
Kami menghapus tindakan yang berhubungan dengan memposting di lain waktu dan menerapkan tindakan kami sendiri untuk memaksanya agar dipublikasikan meskipun memiliki masa depan dengan:
wp_publish_post($post);
Maka yang perlu kita lakukan sekarang hanyalah menampilkan posting di halaman arsip dengan memfilter posts_where
:
function sc_ps_show_future_events_where($where, $that) {
global $wpdb;
if("events" == $that->query_vars['post_type'] && is_archive())
$where = str_replace( "{$wpdb->posts}.post_status = 'publish'", "{$wpdb->posts}.post_status = 'publish' OR $wpdb->posts.post_status = 'future'", $where);
return $where;
}