26

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??

5 Answers 5

17

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
13

The details of custom post types aren't stored anywhere, they're loaded at runtime with each request via register_post_type calls.

4
  • hmmmm, ok, thats y when I was trying to search for the info in the database, was not seeing them, thanks!
    – Noor
    Apr 19, 2012 at 16:16
  • 2
    That is not true at all.
    – Bainternet
    Apr 19, 2012 at 16:52
  • 3
    This may be true of the definition of the custom post type, but it does not address the question of where the data associated with each instance of a custom post type is stored.
    – Bob Jones
    Aug 18, 2014 at 19:49
  • 1
    @BobJones the question mentions the wp_posts table, so it seems pretty clear they know where the post data is stored. but if you have a different interpretation of the question, then perhaps you should add your own answer.
    – Milo
    Aug 19, 2014 at 0:54
11

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
  • This is a better answer to the OP. thx.
    – Kalnode
    Aug 16, 2018 at 15:22
  • Where is the information stored? I cannot find it in the DB
    – axiom
    Mar 5, 2020 at 9:20
  • you could be looking at the wrong database. Look at your wp-config.php file for more info on which database your site is using Mar 5, 2020 at 11:41
5

You can use the function get_post_types to get information on any and all post types that are active at that time. To get info on a specific post type, use get_post_type_object.

1
  • 3
    +1 - To make the returned post types from get_post_types only custom ones the parameter _builtin can be set to false May 25, 2015 at 17:34
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.