How to make a template for a specific post of a custom post type?

As Pages are a special built in Posttype, they get an own template hierarchy. Other “normal” post types and custom post types can only be templated by “single-$posttype.php”. You can however hook into the single_template filter and make wordpress redirect to your template file: function get_custom_post_type_template($single_template) { global $post; if ($post->post_type == ‘account’) { $located … Read more

WP_Query wooCommerce category

You can try the following code to check whether a category with a name exist of not $search_category_name=”T-shirts”; //This gets top layer terms only. This is done by setting parent to 0. $parent_terms = get_terms(‘product_cat’, array(‘orderby’ => ‘slug’, ‘hide_empty’ => false)); foreach ($parent_terms as $pterm) { //check whether the category_name exists if ($search_category_name == $pterm->name) … Read more

WordPress show custom post type on homepage

To display custom post type anywhere, you only need to add this code query_posts(‘post_type=resorts’) just above the while loop. So the while loop will fetch all details of given custom post type and set to the global variable $post. Here is a sample code: <?php query_posts(array( ‘post_type’ => ‘resorts’, ‘showposts’ => 10 ) ); ?> … Read more

Create taxonomy from Custom Post Type

Very Simple Code Snippet for Creating Taxonomy for Custom Post Type Register Custom Post Type function Knowledge_base_init() { $labels = array( ‘name’ => _x( ‘Knowledge bases’, ‘post type general name’, ‘your-plugin-textdomain’ ), ‘singular_name’ => _x( ‘Knowledge base’, ‘post type singular name’, ‘your-plugin-textdomain’ ), ‘menu_name’ => _x( ‘Knowledge bases’, ‘admin menu’, ‘your-plugin-textdomain’ ), ‘name_admin_bar’ => _x( … Read more

Cannot exclude particular post from loop of custom post type

Something like this should work from your functions file as long as you use the correct conditional tag for your CPT archive: function exclude_single_post_cpt($query) { if (is_post_type_archive(‘event’) && $query->is_main_query() && !is_admin() ) { $query->set(‘post__not_in’, array(1646)); } } add_action(‘pre_get_posts’, ‘exclude_single_post_cpt’);

Rewriting hierarchical post type

No, this is not possible. Only pages and posts are able to work without a permalink base. When working with custom post types, you always have a permalink base. That’s just how WordPress works. And the third line of your example can’t work when country is already a child of region, because the parent-child relation … Read more

How to add custom column to Custom post page list?

There is the hook manage_${post_type}_posts_columns which can be used to do just that. Basic example: function wpse188743_events_cpt_columns( $columns ) { $new_columns = array( ‘event_date’ => __( ‘Event Date’, ‘textdomain’ ), ); return array_merge( $columns, $new_columns ); } add_filter( ‘manage_events_posts_columns’ , ‘wpse188743_events_cpt_columns’ ); To fill the column with the related content you additionally have to make … Read more