Pre-Populate $wp_query settings with custom rewrite rules and custom template_redirect

I’ve probably found the solution for the above problem. To pre-populate the global variable $wp_query you have to run the query_posts() function with the correct arguments and reset the $wp_query->post with the function wp_reset_postdata(). This must be done on the template_redirect hook or earlier. class Webeo_Download { protected $downloadId; protected $action; public function setup() { … Read more

Use date in the URL of custom post type

Custom post types can not use the “day/name” permalink structure defined in WordPress permalinks settings. You need to add your own rewrite rules to fit your needs. For example: add_action(‘init’,’my_rewrite_rules’); function my_rewrite_rules(){ // Replace custom_post_type_slug with the slug of your custom post type add_rewrite_rule( ‘custom_post_type_slug/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(.+)/?$’, ‘index.php?custom_post_type_slug=’.$matches[4], ‘top’ ); } Note that I’ve not tested the … Read more