Skip Navigation

[Resolved] List Custom Post Types Posts on Author page

This support ticket is created 3 years, 10 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by goceR 3 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#1903839

Hello
I'm trying to display custom post types posts on the author page (the default one from wp that is listing posts written by the author). Is there any options that Toolset is providing for this?

#1904455

Shane
Supporter

Languages: English (English )

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

Hello,

Thank you for getting in touch.

You can use the function below in order to do this.

<?php 

    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('books', 'posts') );
        remove_action( 'pre_get_posts', 'custom_post_author_archive' );
    }
    add_action('pre_get_posts', 'post_types_author_archives');
    
?>

What you need to do is add the slug for the post type in array. Then add the following to the Toolset Custom code section in Toolset->Settings ->Custom Code and then activate it.

Please let me know if this helps.
Thanks,
Shane

#1907327

I'm using the Astra theme, but when I put this code in it's functions.php file or when I activate the Custom Code in Toolset it gives me a database error.

#1909321

Shane
Supporter

Languages: English (English )

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

Hello,

Can you allow me to have admin access to the site so that I can have a look at this for you ?

I've enabled the private fields for your next response.

Thanks,
Shane

#1912153

Shane
Supporter

Languages: English (English )

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

Hello,

I added the code to the site and included the slugs for your post types in the code and it worked fine.
hidden link

I added the code to Toolset -> Settings->Custom Code

Please let me know if this helps.
Thanks,
Shane

#1912229

My issue is resolved now. Thank you!