First, for the post type (post) that comes standard with wordpress, I added the following code in functions.php to make it possible to access archive.php.

function post_has_archive ($args, $post_type) {
    if ('post' == $post_type) {
        $args ['rewrite'] = true;
        $args ['has_archive'] ='post';
    return $args;
add_filter ('register_post_type_args','post_has_archive', 10, 2);

However, I put the following code to get the link to the list page, but for some reason the URL of the top page is output.

echo get_post_type_archive_link ('post');

I want it to be output as https://xxxxxxxx.com/post
It is in a state where it becomes https://xxxxxxxx.com/.

Does get_post_type_archive_link not work for standard post types?
Or do I have to use another function?

  • Answer # 1

    If you follow the source, if the argument is'post'has_archiveThe function ends without checking the value of.
    (Although not directly relatedhas_archiveIstrue/falseI think that)

    URLpost_type_archive_linkIf you overwrite it with a hookget_post_type_archive_linkYou can get it, but I think it's faster to use a custom post type instead of the standard post type.

    [Get_post_type_archive_link () | Function | WordPress Developer Resources]

    [Link-template.php in tags/5.5.1/src/wp-includes – WordPress Trac]

     if ('post' === $post_type) {
           $show_on_front = get_option ('show_on_front');
           $page_for_posts = get_option ('page_for_posts');
           if ('page' === $show_on_front&&$page_for_posts) {
               $link = get_permalink ($page_for_posts);
           } else {
               $link = get_home_url ();
          /** This filter is documented in wp-includes/link-template.php * /
           return apply_filters ('post_type_archive_link', $link, $post_type);