I am trying to build a speaking URL for a custom post type in Wordpress storing event dates. I would like to have the following scheme for event-URLs:
/events/2013-12-24-christmas/
/events/2013-12-31-newyearseve/
The date is not the standard published date, it is instead a date stored in a meta-field: the date on which the event takes place.
I tried to achieve it with a snippet I used to rewrite another custom post type and it looked promising - but the only problem is: I can't get the post-id to query for the meta values :(
Here's the rewrite code so far:
function create_post_type_events {
[...custom-post-type...]
register_post_type('my_events', $args);
global $wp_rewrite;
$permalink_structure = '/events/2013-12-24-%my_events%';
$wp_rewrite->add_rewrite_tag("%my_events%", '([^/]+)', "my_events=");
$wp_rewrite->add_permastruct('my_events', $permalink_structure, false);
}
add_action('init', 'create_post_type_events');
The date is obviously hard-coded and needs to be replaced.
I tried $post, $wp_query, globalizing, get_queried_object()... nothing seems to help.
So, how (and is it actually possible?) can I get the post-ID for further querying?