Dynamic assign a custom template to custom post type posts

locate_template search template only in themes then to use a file outside themes, you can use the filter template_include like that add_filter(“template_include”, function ($template) { $post = get_queried_object(); if ( is_single() && (“features” === $post->post_type) ) { // absolute path to the template file $template = __DIR__ . “/../../template/my_features_template.php”; } return $template; });

How to get all posts related to particular category name on button click?

How to get category wise all post in WordPress? Add below code in taxonomy-“yourtaxonomyname”.php for ex : file name : taxonomy-event-category.php & Post type : events & taxonomy name : event-category <?php $category_object = get_queried_object(); $category_taxonomy = $category_object->taxonomy; $category_term_id = $category_object->term_id; $category_name = $category_object->name; $category_description = $category_object->description; $category_slug = $category_object->slug; $post_type=”events”; $paged = (get_query_var(‘paged’)) ? … Read more

Default Category Page not showing custom post type which has taxonomy category

The default query doesn’t include custom post types. You have to use pre_get_posts hook to modify your query. Hope this solves your issue function custom_posttype_query( $query ) { if( (is_category() || is_tag()) && $query->is_archive() && empty( $query->query_vars[‘suppress_filters’] ) ) { $query->set( ‘post_type’, array( ‘post’, ‘gallery’ )); } return $query; } add_filter( ‘pre_get_posts’, ‘custom_posttype_query’ );