Custom author page for custom role
-
I have created my own author page (author.php) where all the posts from that author is listed. The link to that page is – localhost/abc/author/new-user/.
This is working fine in localhost. But the same code is not working in my live site. The url in the live site is same as localhost- example.com/author/new-user/.
When visited this url, it redirects to archive.php and nothing found message is displayed even though posts are there for the user.The problem with the code is, If I remove
$user_roles[0] == 'trip_vendor'
from if condition to make it justif( is_author() )
then it works in live site as well. I am surprised why thisif( $user_roles[0] == 'trip_vendor' && is_author() )
is returning false on live site and not on local.I have a function to handle this. Below is the code how I am handling this.
add_filter( 'template_include', array( $this, 'abc' ),100 ); function abc( $template_path ) { global $post; $user_meta = get_userdata($post->post_author); $user_roles = $user_meta->roles; if( $user_roles[0] == 'trip_vendor' && is_author() ) { if ( $theme_file = locate_template( array ( 'author.php' ) ) ) { $template_path = $theme_file; } else { $template_path = VENDOR_BASE_PATH . '/public/vendor-templates/profile/author.php'; } } }
Hopefully someone can shade some light on this.
Thank you.
- The topic ‘Custom author page for custom role’ is closed to new replies.