Show Custom Post Types on the Homepage

Custom post types are commonly used in WordPress sites, but they don’t show on the homepage or in the archive pages unless you write code to do that. I’ve put together some code that is smart about detecting your public custom post types and automatically adding them to your homepage and archive pages:

Create WordPress Custom Post Type Archive PageTemplates

Post Type Templates Custom Post Type Templates archive-{post_type}.php single-{post_type}.php archive-{post_type}.php  If the custom post type were ‘product’, WordPress would look for archive-product.php to display the archive of posts. single-{post_type}.php  If the custom post type were ‘product’, WordPress would look for single-product.php to display the single or permalink of the post. If these files are not […]

How to Create a Custom Post Types Archive Page in WordPress

If you want to show your custom post types on your category archive pages? Add this to your functions.php file: add_filter(‘pre_get_posts’, ‘query_post_type’); function query_post_type($query) { if(is_category() || is_tag()) { $post_type = get_query_var(‘post_type’); if($post_type) $post_type = $post_type; else $post_type = array(‘post’,’myCustomPostTymeName’); // replace myCustomPostTymeName to your custom post type $query->set(‘post_type’,$post_type); return $query; } } Now change […]