Skip Navigation

[Resolved] Author archive for custom post type

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to add custom post types to the Author Archive for their users.

Solution:
This can be done by using the Hook below.

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('nota', 'post') );
    remove_action( 'pre_get_posts', 'custom_post_author_archive' );
}
add_action('pre_get_posts', 'post_types_author_archives');

Add the above to the functions.php file and just add your post type slug to the post_type array.

This support ticket is created 4 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Jos 4 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#2013905

Jos

I have a custom post type "nota"
hidden link

I am trying to create the author archive but the loop doesn't show nota posts:
There were no posts found to display for this WordPress Archive's query.
hidden link

Here is a post test
hidden link

How can I provide you with credentials?

Please point the subdomain magis.iteso.mx to the IP:
148.201.128.118 magis.iteso.mx

#2014085

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jos,

Thank you forgetting in touch.

In order to add your custom posts to the author archive you will need to use this hook below.



    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('nota', 'post') );
        remove_action( 'pre_get_posts', 'custom_post_author_archive' );
    }
    add_action('pre_get_posts', 'post_types_author_archives');

Add this to your Toolset custom code in Toolset->Settings -> Custom Code and activate it. Once you've done this then your custom post type should now display in the author archive.

Thanks,
Shane

#2015131

Jos

My issue is resolved now. Thank you!