As I mentioned in my comment, you can use add_rewrite_endpoint
to accomplish this.
First, add the endpoint:
function wpa_author_endpoints(){
add_rewrite_endpoint( 'liked-posts', EP_AUTHORS );
}
add_action( 'init', 'wpa_author_endpoints' );
After flushing rewrite rules (visit your Settings > Permalinks
page in admin), author URLs can now be appended with /liked-posts/
.
Next, add a filter to author_template
to load a different template for these requests. This checks if the request has set the liked-posts
query var, and loads the template liked-posts.php
if it exists:
function wpa_author_template( $template="" ){
global $wp_query;
if( array_key_exists( 'liked-posts', $wp_query->query_vars ) )
$template = locate_template( array( 'liked-posts.php', $template ), false );
return $template;
}
add_filter( 'author_template', 'wpa_author_template' );
Within that template, you can use get_queried_object
to fetch the author data for the queried author, which you can use in additional queries to load your author data.
EDIT – pagination doesn’t work with an endpoint, because anything after the endpoint gets put into the endpoint query var. so to get the page number, just extract it from the query var:
if( strpos( $wp_query->query_vars['liked-posts'] ,'page') !== false ) {
echo substr( $wp_query->query_vars['liked-posts'], 5 );
}