Create a custom archive page for a custom post type in a plugin

What you need is hooking template_include filter and selectively load your template inside plugin. As a good practice, if you plan to distribute your plugin, you should check if archive-my_plugin_lesson.php (or maybe myplugin/archive-lesson.php) exists in theme, if not use the plugin version. In this way is easy for users replace the template via theme (or … Read more

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 use a custom post type archive as front page?

After you have set a static page as your home page you can add this to your functions.php and you are good to go. This will call the archive-POSTTYPE.php template correctly as well. add_action(“pre_get_posts”, “custom_front_page”); function custom_front_page($wp_query){ //Ensure this filter isn’t applied to the admin area if(is_admin()) { return; } if($wp_query->get(‘page_id’) == get_option(‘page_on_front’)): $wp_query->set(‘post_type’, ‘CUSTOM … Read more