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
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
The details of custom post types aren't stored anywhere, they're loaded at runtime with each request via register_post_type
calls.
-
hmmmm, ok, thats y when I was trying to search for the info in the database, was not seeing them, thanks!– NoorCommented Apr 19, 2012 at 16:16
-
2
-
3This 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. Commented 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.– MiloCommented Aug 19, 2014 at 0:54
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 |
+---------------------+-----------------------+--------------+--------------+--------+---------------------+
-
-
-
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 Commented Mar 5, 2020 at 11:41
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
.
-
3+1 - To make the returned post types from
get_post_types
only custom ones the parameter_builtin
can be set tofalse
Commented May 25, 2015 at 17:34
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.