Skip Navigation

[Resolved] filtering custom post types by author

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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 1 year, 7 months ago.

Assisted by: Waqar.

Author
Posts
#2664733

Tell us what you are trying to do?
I want to create an author page that displays all posts the author created. These are custom post types . Currrently if I display the authors posts, it only displays default WP posts.

Is there any documentation that you are following?
no

Is there a similar example that we can see?
no

What is the link to your site?
currently only on a local staging environment

#2664863

Hi,

Thank you for contacting us and I'd be happy to assist.

We have an internal ticket to include this feature of post type selection, for the archives created using the Toolset.

Although, I don't have a time estimate to share at the moment, for now, you can include this custom code, to include more post types for the author archives:


function custom_pre_get_posts_author_archives($query) {
	if ( ! is_admin() && $query->is_main_query() && $query->is_author ) {
		// Allow only selective post types to display in author's archive
		$query->set( 'post_type', array('books', 'shops') );
	} 
}
add_action('pre_get_posts', 'custom_pre_get_posts_author_archives');

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

In this example snippets, I've used the post type slugs 'books' and 'shops' to be included in the author archives. On your website, you can replace them to match the slugs of your target post types.

I hope this helps and please let me know if you need further assistance.

regards,
Waqar