Custom Post Type Archives by Year & Month?

Yes, you can. All you need is make a filter for wp_get_archives(); so it accepts post_type parameter: function my_custom_post_type_archive_where($where,$args){ $post_type = isset($args[‘post_type’]) ? $args[‘post_type’] : ‘post’; $where = “WHERE post_type=”$post_type” AND post_status=”publish””; return $where; } then call this: add_filter( ‘getarchives_where’,’my_custom_post_type_archive_where’,10,2); Whenever you want to display archive by custom post type, just pass the post_type args: … Read more

How to rewrite URI of custom post type?

This is what I use to rewrite custom post type URLs with the post ID. You need a rewrite rule to translate URL requests, as well as a filter on post_type_link to return the correct URLs for any calls to get_post_permalink(): add_filter(‘post_type_link’, ‘wpse33551_post_type_link’, 1, 3); function wpse33551_post_type_link( $link, $post = 0 ){ if ( $post->post_type … Read more

How to get current get_post_types name?

You’ll need the post object somehow, or, alternatively the queried object on post type archives. On a singular page you might do: $post = get_queried_object(); $postType = get_post_type_object(get_post_type($post)); if ($postType) { echo esc_html($postType->labels->singular_name); } Or in the loop: $postType = get_post_type_object(get_post_type()); if ($postType) { echo esc_html($postType->labels->singular_name); } In post type archives: $postType = get_queried_object(); echo … Read more

Restrict custom post type to only site administrator role

register_post_type() accepts a parameter capabilities in its arguments. See get_post_type_capabilities() for possible values. From the comments: By default, seven keys are accepted as part of the capabilities array: edit_post, read_post, and delete_post are meta capabilities, which are then generally mapped to corresponding primitive capabilities depending on the context, which would be the post being edited/read/deleted … Read more