In my WordPress v5.7, currently I have two custom post_type: song, & poem.
I have a custom
author.php template with author profile and latest 10 posts from both post_type with no pagination, as required by site design. Here is the author template at pastebin (https://pastebin.com/kCrYebcD).
If the author has more than 10 posts from both post_type, I want to show all posts from both post_type in
archive.php template with pagination. Here is the archive template at pastebin (https://pastebin.com/twkWn5Bc).
author.php I have this URL to redirect to all post archive page:
$author_page_link = esc_url(get_author_posts_url(false, ID->user_nicename)); echo '<a href="' . $author_page_link . '?post_type=song&post_type=poem">All</a>';
This is how the URL constructs:
The above URL is redirecting back to
author.php page. If I use only any one post type as below, the URL stays in the
<a href="' . $author_page_link . '?post_type=poem">All</a>
How can I show a single author’s all posts from selective custom post_type in the
This is how I have solved:
I have created a custom page template
author-all-posts.php with page slug
all. I have used the custom URL parameters as below:
In my custom page template, I have the below code:
// get the author ID $authorID = $_GET['author_id'];
WP_Query to get all the posts from multiple post_types:
$all_args = array( 'author' => $authorID, 'post_type' => array('song', 'poem'), 'posts_per_page' => -1 ); query_posts($all_args);
I am working on
add_rewrite_rule to red rid of the ugly URLs next.