This is an answer I re-porpoised from a question that was abandoned. I thought this will help you solve this issue
By default, all custom post types are excluded from the main query, that is why you don’t see any posts when going to the front end author page. To accomplish this, you will need to modify the main query to include these post type/s. For this purpose, you are going to use the pre_get_posts
action hook. You will also use the conditional tag is_author()
to check that you are on the author archive page. (I’ve tested this code using my custom post types event_type
and cameras
, so just change this accordingly)
function custom_post_author_archive($query) {
if ($query->is_author() && $query->is_main_query() )
$query->set( 'post_type', array('event_type', 'cameras', 'post', 'page') );
}
add_action('pre_get_posts', 'custom_post_author_archive');
To tackle the problem of post count in the back end, I think it will be a good idea to unset the posts
column in the authors page, and then to replace it with a new column that will count all the post types, ie event_type, post and page. You can edit this accordingly
Here you will make use of manage_users_columns
and manage_users_custom_column
which is not very well documented.
function add_extra_user_column($columns) { //Add CPT Column for events and remove default posts column
unset($columns['posts']);
return array_merge( $columns,
array('foo' => __('Posts')) );
}
add_filter('manage_users_columns' , 'add_extra_user_column');
function add_post_type_column( $value, $column_name, $id ) { //Print event_type value
if( $column_name == 'foo' ) {
global $wpdb;
$count = (int) $wpdb->get_var( $wpdb->prepare(
"SELECT COUNT(ID) FROM $wpdb->posts WHERE
post_type IN ('event_type', 'cameras', 'post', 'page') AND post_status="publish" AND post_author = %d",
$id
) );
if ( $count > 0 ) {
$r = "<a href="https://wordpress.stackexchange.com/questions/155677/edit.php?author=$id">";
$r .= $count;
$r .= '</a>';
} else {
$r = 0;
}
return $r;
}
}
add_filter( 'manage_users_custom_column', 'add_post_type_column', 10, 3 );