Show date as permalink for custom post type instead of post name

I created a custom post type and specified a rewrite to change the permalink to /old-donuts/. See code below:

function donut_newsletters_post_type() {

$labels = array(
‘name’ => ‘🍩 Newsletters’,
‘singular_name’ => ‘🍩 Newsletter’,
‘add_new’ => ‘Add 🍩’,
‘add_new_item’ => ‘Add New 🍩’,
‘edit_item’ => ‘Edit 🍩’,
‘new_item’ => ‘New 🍩’,
‘view_item’ => ‘View 🍩’,
‘search_item’ => ‘Search Daily 🍩s’,
‘not_found’ => ‘No 🍩s found’,
‘not_found_in_trash’ => ‘NO 🍩s found in the trash..that would be a sin’
);
$args = array(
‘labels’ => $labels,
‘public’ => true,
‘has_archive’ => false,
‘publicly_queryable’ => true,
‘query_var’ => true,
‘rewrite’ => array(
‘slug’ => ‘old-donuts’
),
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘supports’ => array(
‘title’,
‘editor’,
‘excerpt’,
‘thumbnail’
),
‘taxonomies’ => array(‘post_tags’),
‘menu_position’ => 0,
‘exclude_from_search’ => true,
‘menu_icon’ => ‘dashicons-email’
);

register_post_type(‘donut_newsletters’, $args);
}

add_action(‘init’, ‘donut_newsletters_post_type’);

Now let’s say I go create a new post and title it “test”, the permalink defaults to https://thedonut.co/old-donuts/test

I don’t want this. What I do want is for the permalink to instead default to a custom date structure like this:

https://thedonut.co/old-donuts/2019-08-24/

I also want the keep the permalink modifiable by the editor so that in the case that he/she had to create a post the day before they want it to go live, they can change the day value to the next day.

Please don’t send me to a plugin. I’ve tried custom post type permalinks plugin and it does what i want, but it doesn’t allow modification of the permalink after the post is published.

Read more here:: Show date as permalink for custom post type instead of post name

Leave a Reply

Your email address will not be published. Required fields are marked *