Tell us what you are trying to do?
I have a custom post type and in that post type I have a bunch of posts. I don't have any WordPress default posts. I created a Toolset archive to show my author custom posts.
But in the author archive, the custom posts aren't showing. How can I show those posts in my author archive?
Author archive: hidden link
Hello,
You can use custom codes to add custom post types into the author archive page, for example, see below test site:
Login URL:
hidden link
1) Dashboard-> Toolset-> Settings-> Custom codes, add an item, with below codes:
function post_types_author_archives($query) {
if ($query->is_author)
// Add 'books' CPT and the default 'posts' to display in author's archive
$query->set( 'post_type', array('test-cpt-1', 'post') );
remove_action( 'pre_get_posts', 'custom_post_author_archive' );
}
add_action('pre_get_posts', 'post_types_author_archives');
2) Test it in frontend:
hidden link
It works fine, you can find post of pos type "test-cpt-1" in it
If I have another custom post type test-cpt-2 and want to show posts of both of the post types (test-cpt-1, test-cpt-2) in the archive, where will I add it in the code?
The code above is adding the post types to all the author archives. I want to add those post types to specific author archives only ('fahim', 'farhan'). How can I do that?
Q1) want to show posts of both of the post types (test-cpt-1, test-cpt-2) in the archive
You can add more post type slugs into the PHP array, for example:
array('test-cpt-1', 'test-cpt-2', 'post')
Q2) I want to add those post types to specific author archives only
You can use function is_author() to as condition, for example, change this line from:
if ($query->is_author)
To:
if ($query->is_author && is_author(array('fahim', 'farhan')))
More help:
https://developer.wordpress.org/reference/functions/is_author/
My issue is resolved now. Thank you!