Home>

At the company I work for now,
We are building a web magazine using Wordpress.

Create a new custom post type,
Use that custom post and
The writer (Author) will continue to write articles.

So, for each article writer,
I would like to create a custom post archive page.

I think it can be implemented somehow using HTML and PHP (WP_Query sub-loop).
I would like to implement it in a simpler way.

It may be a case of taking over maintenance to a successor,
This is because from the standpoint of maintainability, we think that the simplest method is good.

Specifically, using the plug-in "Custom Post Type Permalinks",
Simply hit the URL of the archive page and
I want to display an archive page for each writer.
(The main loop of WP_Query is a custom post
I want to get specific writer articles)

Tried

Using the plug-in "Custom Post Type Permalinks",
We have created an archive page for each custom post type custom taxonomy.


Custom post type name: article
Custom taxonomy: category_article
Permalink setting in "Custom Post Type Permalinks":
(Domain)/article/category_article /% category_article% /% post_id%/

With the above settings,
At the URL "(domain)/article/category_article /% category_article%"
The archive page could be displayed.

In a similar way,
Did you know how to display an archive page for each author of a custom post type?

  • Answer # 1

    You can use a contributor template and use pre_get_posts to specify that the custom post type is displayed in the main loop.

  • Answer # 2

    For example, below the domain
    /? post_type = hoge&author = 4
    You can get a list of custom post types by author.
    The post_type = value is a custom post type slug
    The value of author = is the ID of the user (author)

    After confirming that, I feel like adding a rewrite rule.

    Add the following to theme functions.php

    function authorUrlRewrite () {
      add_rewrite_rule ('^ hoge/author/([^ /] *) /? $', 'index.php? post_type = hoge&author_name = $matches [1]', 'top');
    }
    add_action ('init', 'authorUrlRewrite');

    To apply, after uploading functions.php,
    Open Settings>Permalink Settings and do nothing and press the Save Changes button.
    You should see a list of posts under/hoge/author/username/under your domain.