Skip Navigation

[Resolved] author page archive custom posts not showing

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by fahimS-2 1 year, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#2567877
Screenshot_8.jpg
Screenshot_7.jpg

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

#2568117

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

#2568209

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?

#2568601

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?

#2569071

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/

#2569359

My issue is resolved now. Thank you!