6

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
4
  • Because it doesn't make sense to have archive for posts. FALSE is set by default to all post types. Commented Jun 6, 2012 at 12:00
  • 2
    Posts have archives, they are displayed on the homepage with a fresh install.
    – bpierre
    Commented Jun 6, 2012 at 12:31
  • has_archive Enables post type archives. Will use $post_type as archive slug by default. Default: false Note: Will generate the proper rewrite rules if rewrite is enabled. Also use rewrite to change the slug used. It means that there should be archive with slug http:://mysite.com/post/ - do you have such archive? Commented Jun 6, 2012 at 12:49
  • 2
    Got it, has_archive should have been named has_archive_slug. Thank you.
    – bpierre
    Commented Jun 6, 2012 at 12:57

1 Answer 1

7

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

1
  • 1
    With has_archive to false you are able to use a custom page as archive.
    – Tobi G.
    Commented Feb 18, 2021 at 14:53

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.