Number of Custom Post Types WP

How Many Custom Post Types Do You Have in Your WordPress Site?

Do you need to try a WordPress theme? Create a temp site now!

Sharing is caring!

WordPress is a versatile platform that allows you to create various types of content through its default and custom post types. While the standard post types like 'posts' and 'pages' cater to most needs, custom post types enable you to tailor your content structure for more specific requirements. This guide will help you identify the custom post types in your WordPress site and explain their uses.

Default WordPress Post Types:

  • Posts: Regular blog posts or articles. They are time-based entries listed in reverse chronological order.
  • Pages: Static content that isn’t time-sensitive, such as 'About Us' or 'Contact' pages.
  • Attachments: Media files uploaded to your WordPress site, such as images and documents.

Newer WordPress Post Types:

  • wp_global_styles: This post type is used for storing global styles settings in WordPress, allowing for site-wide style customization.
  • wp_navigation: This post type manages navigation menus within WordPress, providing a structured way to handle menus across the site.

Custom Post Types:

  • Portfolio: A custom post type to showcase projects, artworks, or case studies. It’s especially useful for freelancers and agencies.
  • Products: For eCommerce sites, a 'product' post type helps manage and display items for sale, integrating with shopping cart functionalities.
  • Testimonials: Display customer reviews and feedback. This post type helps build credibility and trust for your business.
  • Events: Manage and display upcoming events with details like dates, locations, and descriptions. Useful for businesses or organizations that hold regular events.
  • FAQs: Frequently Asked Questions can be managed separately, allowing better organization of common inquiries and their answers.

To find out how many custom post types you have in your WordPress site, you can use a SQL query to list all distinct post types, excluding the default ones such as 'post', 'page', and 'attachment'. Here's how you can do it:

Access Your Database: You can use a tool like phpMyAdmin or Adminer, or connect to your database using a command-line interface (mysql).
Run the following SQL query to get the distinct custom post types:

SELECT DISTINCT(post_type)  FROM `wp_posts` WHERE `post_type` NOT in ('post', 'page', 'attachment');

wp_ is the default database table prefix. You need to check wp-config.php of your WordPress site to find the actual prefix.

SQL Query: The query fetches all unique post types excluding 'post', 'page', and 'attachment'.

Getting the number of Custom Post Types using WP-CLI

WP-CLI is a great command line tool to do varous WordPress related actions.

If you have access to SSH you can also run the SQL query above via the command line as follows

cd /path/to/your/wordpress/
wp db query "SELECT DISTINCT(post_type) FROM wp_posts WHERE post_type NOT IN ('post', 'page', 'attachment');"

To find all WordPress post types including the built-in ones. Run this wp-cli command.
If you're running a blog with minimalistic theme and plugins you'll only see the default ones.

wp db query "SELECT DISTINCT(post_type) FROM wp_posts"
+------------------+
| post_type        |
+------------------+
| page             |
| post             |
| wp_global_styles |
| wp_navigation    |
+------------------+

Why do you need this info?

This is useful to see how many posts you have in the WordPress site especially if you have just inherited your WordPress site. If you recognize a post type that shouldn't be there you can delete some records. wp_posts table is one of the most important tables in WordPress.

Sharing is caring!

Do you need to try a WordPress theme? Create a temp site now!
This code shared in this post/site is provided "AS IS" without any warranties or guarantees of any kind. The authors and distributors of this code cannot be held responsible for any damage, data loss, or other issues that may arise from its use. It is strongly recommended that you test this code in a staging environment before deploying it to a live site. Always ensure you have proper backups and understand the implications of running this code on your WordPress installation. Use at your own risk.

Leave a Comment

Your email address will not be published. Required fields are marked *

The new new server is up and running. Enjoy!