Skip to main content
4 of 4
added 28 characters in body
kaiser
  • 50.8k
  • 27
  • 150
  • 244

How to create a template for a custom URI associated with the user

I am working on a site where I am using a plugin called Favorite Posts so logged-in users can add a post (a custom post type) to their favorites.

I created a page called my-favorites which allows the logged-in user to see the posts he has favorited.

Now I need to create a page which allows the another user or visitor to check this user's favorites.

So I need to be able to do three things:

  1. Get a function related to author that returns a link like example.com/user/username which I can append to /favorites to get the link - example.com/user/username/favorites (the_author_link() and get_the_author() link seems to link to the website and the_author_posts_url() outputs the a tag with the name. any function to just get the url or maybe modify author to show user instead?)

  2. Get WordPress to use a template called favorites.php to display this page. (If the structure matches, then how do I tell WordPress which template to use?)

  3. Get the user id of the user in order to show his/her favorites to the visitor. Right now, I use the [favorite-post] shortcode in my template file and can pass a parameter called

    [favorite-post user_id = ""]
    

    Will it automatically get the user id if the page is branched out from /author?

I found this article but it still deals with custom post types and query_vars which I am not using. How do I make it work for the favorites page? Most other similar questions asked here were solved using a slug for the custom post type or taxonomy.