Where are wordpress custom types stored?

Where are custom types stored? Because when a custom type is created, in wp_posts, the post type is set to the <new_custom_post_type>. But where are the details of the new custom post type stored??

Related posts

Leave a Reply

5 comments

  1. I finally found the custom post type data. It is stored in the wp_post table where post_type = custom post type (e.g. “products”). The field (column) data is stored in wp_postmeta where the meta_key is the column name and meta_value is the column value.

    This query will bring back all data associated with the custom post type “products”:

    SELECT P.ID, P.post_title, M.meta_key, M.meta_value
    FROM wp_posts AS P
    INNER JOIN wp_postmeta AS M ON M.post_id = P.ID
    WHERE P.post_type = 'products' and P.post_status = 'publish'
    ORDER BY post_title, meta_key
    
  2. As mentioned by @milo in this answer

    Post Types aren’t actually stored separately in the database however that being said…

    via SQL

    you can view all saved PUBLIC post types using the following sql query

    SELECT DISTINCT( post_type ) FROM wp_posts;
    

    Which will output something similar to:

    +----------------------+
    | post_type            |
    +----------------------+
    | attachment           |
    | competition          |
    | custom_css           |
    | customize_changeset  |
    | deprecated_log       |
    | experts              |
    | magazine             |
    | nav_menu_item        |
    | page                 |
    | post                 |
    | revision             |
    +----------------------+
    

    via WP CLI

    Additionally if you have access to wp cli, you can run:

    wp post-type list
    

    Which will output something like:

     +---------------------+-----------------------+--------------+--------------+--------+---------------------+
     | name                | label                 | description  | hierarchical | public | capability_type     |
     +---------------------+-----------------------+--------------+--------------+--------+---------------------+
     | post                | Posts                 |              |              | 1      | post                |
     | page                | Pages                 |              | 1            | 1      | page                |
     | attachment          | Media                 |              |              | 1      | post                |
     | revision            | Revisions             |              |              |        | post                |
     | nav_menu_item       | Navigation Menu Items |              |              |        | post                |
     | custom_css          | Custom CSS            |              |              |        | post                |
     | customize_changeset | Changesets            |              |              |        | customize_changeset |
     | deprecated_log      | Deprecated Calls      |              |              |        | post                |
     +---------------------+-----------------------+--------------+--------------+--------+---------------------+
    
  3. WordPress default comes with some sample post types like pages, posts etc. WordPress has given option to create our own custom post types also. Both default & custom posts are stored in single table “wp_posts” by differentiating all posts types based on “post_type” column in “wp_posts” table.

    Eg:
    pages–> post_type=”page”,
    testiminials–> post_type=”testimonials”
    etc

    To grab more information about this post_types, which would be available at “wp_postmeta ” table.