has_archive=false on the default post type

On the default post type, why does the has_archive property equals to FALSE?

$type_obj = get_post_type_object('post');
var_dump($type_obj->has_archive); // FALSE

Related posts

Leave a Reply

1 comment

  1. Late answer.


    has_archive applies only for the rewrite arguments.

    In Detail

    If has_archive is set to true, then the $archive_slug will get set to the rewrite['slug'] argument. If then a rewrite['with_front'] arg is set, then this one will get prepended. The result of this will then get added as rewrite rule:

    add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' );
    

    If feeds are set to true and has_archive also, then you’ll also get rewritten rules for feeds:

    add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
    add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
    

    The same principle applies for rewrite['pages']:

    add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' );
    

    Summed up:

    If you ain’t got has_archive set to true, then any try to add rewrites for feeds, pages or archives will end up with a big ?.