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 :

  1. 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'); var_dump($posty_type);

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.

  1. 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 ?
  • 1
    the post types definitions are stocked in the PHP code. in the core and in the plugins. it's the reason why in plugins, the call to register_post_type must be done on every call. – Kaperto Nov 9 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.