Best way to flush_rewrite_rules for custom post type, in a mu-plugins plugin?

The flush_rewrite_rules function is reliable in some contexts like a theme or a plugin based on hooks but I’m not sure if it works for a mu-plugin My statement is based on the fact that WordPress is initialized in this way: call the wp-settings.php file call the do_action( ‘muplugins_loaded’ ); hook, here your plugin is … Read more

How to set a custom post type to have viewable future posts

I’ve been able to solve this myself. My entire code for registering the CPT: <?php add_action( ‘init’, ‘events_post_type_register’ ); function events_post_type_register() { $post_type = “events”; $labels = array( ‘name’ => _x(‘Events’, ‘post type general name’, ‘project_X’), ‘singular_name’ => _x(‘Event’, ‘post type singular name’, ‘project_X’), ‘add_new’ => _x(‘Add New’, ‘event’, ‘project_X’), ‘add_new_item’ => __(‘Add New Event’, … Read more

Set post date before 1970

Do not use the post_date field for anything it isn’t made for. Use a post meta field instead. The post_date is bound to post_date_gmt, you would get strange side effect even you could get an earlier date into that. So create post meta fields and query those per tax query. Ignore the default field. In … Read more

Custom Post Type Permalink / Rewrite not working immediately

Use the function flush_rewrite_rules() for set the rewrite rules new, but not with your code on init-hook, only on activation plugin or theme! See more in my post: http://wpengineer.com/2044/custom-post-type-and-permalink/ global $wp_rewrite; $wp_rewrite->flush_rules(); Flush rules only on activation (and deactivation). Don’t do it on any other hook. register_activation_hook()

Custom Post Types and template_redirect

You should be using the template_include filter for this: add_filter(‘template_include’, ‘wpse_44239_template_include’, 1, 1); function wpse_44239_template_include($template){ global $wp_query; //Do your processing here and define $template as the full path to your alt template. return $template; } template_redirect is the action called directly before headers are sent for the output of the rendered template. It’s a convenient … Read more