Where does get_post_types() get the data from?

I was going through the WP Core trying to understand how URLs are parsed to SQL query . So , I found in wp-includes/class-wp.php , in the method WP::parse_request() a call is made to get_post_types();

foreach ( get_post_types( array(), ‘objects’ ) as $post_type => $t ) {
if ( is_post_type_viewable( $t ) && $t->query_var ) {
$post_type_query_vars[ $t->query_var ] = $post_type;

My questions are :

from which table does get_post_type() ; gets it’s data from ? I was thinking it is from the table wp_posts but its not . In the database in the table wp_posts I added a post manually with a random post type but this post_type doesnt show when I var_dump get_post_types inside wp-includes/class-wp.php

$posty_type = get_post_types(array(), ‘objects’);

It only shows these WP_Post_Type :

post:page: attachment: revision: nav_menu_item: custom_css: customize_changeset: oembed_cache: user_request: wp_block:

It doesnt show the newley added post_type in wp_posts table.

I was thinking the code $post_type_query_vars[ $t->query_var ] = $post_type; was to set $post_type_query_vars array with the query variables of all the post types . But in my var_dump the $t->query_var for all the WP_Post_Types are false so my $post_type_query_vars will not be set at all ? Could somebody shed light when would be $t->query_var to be true and how is the code above supposed to work ?

Read more here:: Where does get_post_types() get the data from?

Leave a Reply

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