WordPress hwk Codes Enregistrer un Post Type avec Archive Uniquement, sans vue Single

Enregistrer un Post Type avec Archive Uniquement, sans vue Single

25 April 2018
<?php
// Register Post Type
add_action('init', 'hwk_post_type_exemple', 0);
function hwk_post_type_exemple(){
register_post_type('exemple', array(
'hierarchical' => false, // true | false. See 'post_row_actions' & 'page_row_actions' filters
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'rewrite' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'has_archive' => 'exemples'
));
}
// Remove Single Rewrite Rules
// '{permastruture}_rewrite_rules' filter
add_filter('exemple_rewrite_rules', '__return_empty_array');
// Remove Post Type List Action 'View'
add_filter('page_row_actions', 'hwk_post_type_exemple_row_actions', 10, 2); // if post_type is hierarchical
add_filter('post_row_actions', 'hwk_post_type_exemple_row_actions', 10, 2); // if post_type is not hierarchical
function hwk_post_type_exemple_row_actions($actions, $post){
if(!isset($post->post_type) || $post->post_type != 'exemple')
return $actions;
unset($actions['view']);
return $actions;
}


Konrad Chmielewski

Evangeliste WordPress & Full Stack Developer depuis 10 années.