Tutorials WordPress How to Include WordPress Custom Post Types to Archive Page

How to Include WordPress Custom Post Types to Archive Page

The default WordPress author archive page template displays only default post types. The custom posts are not included. The following WordPress code snippet will help you to include WordPress custom post types to author archive page.

Add the following snippets to your WordPress theme functions.php file:

add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {

	if ( is_author() && $query->is_main_query()) {
		$query->set( 'post_type', array( 'post', 'post_type1', 'post_type2' ) );
	}
	return $query;
}

Save the changed functions.php and visit your your WordPress author archive.

Total
0
Shares
guest
0 Comments
Inline Feedbacks
View all comments
Previous Post
Facebook SDK

Facebook Encouraging Developers to Migrate to Facebook SDK v4

Next Post
SEO-A Beginners Guide to Search Engine Optimisation

What is SEO? A Beginners Guide to Search Engine Optimisation

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
0
Would love your thoughts, please comment.x
()
x