Create category only for custom post type

I would say that you need to also create a custom taxonomy if you want it to be limited to the one post type. “Categories” is already connected to posts by default. From the WordPress Codex function people_init() { // create a new taxonomy register_taxonomy( ‘people’, ‘post’, array( ‘label’ => __( ‘People’ ), ‘rewrite’ => … Read more

Use WordPress page instead of post type archive

This one’s actually pretty easy. When you declare your post type using register_post_type, you need to add a new argument for ‘has_archive’. So you’ll add in something to the effect of: ‘has_archive’ => ‘about-cool-post-types’ Then, go to your Settings > Permalinks to flush them and it should work. I tested it locally, and this seems … Read more

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

Delete all posts of a custom post type—efficiently

You can delete all post via $wpdb DELETE FROM wp_posts WHERE post_type=”post_type”; DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT id FROM wp_posts); DELETE FROM wp_term_relationships WHERE object_id NOT IN (SELECT id FROM wp_posts) or use this query replace it with {{your CPT}} with your Custom Post Type DELETE a,b,c FROM wp_posts a LEFT JOIN … Read more

How do I set the default admin sort order for a custom post type to a custom column?

Solution from a cross post over at StackExchange from @birgire: The problem is that you run the clientarea_default_order callback too late. To fix that you only have to change the priority from the default one that’s 10: add_action( ‘pre_get_posts’,’clientarea_default_order’); to the priority of 9: add_action( ‘pre_get_posts’,’clientarea_default_order’, 9 ); But you don’t actually need two pre_get_posts … Read more