Tell us what you are trying to do?
I've created a custom post type called "freelancers". This serves as a profile for when someone registers as a freelancer.
I've made it so that the profile is created upon registration. Also, that the user can only create 1 of these posts.
I've also created 2 post types jobs and a (child) post type offers. A freelancer can send an offer and this shows on the single page. This is all workin correctly.
However when showing an offer the name of the freelancer shows up. I'd like to link that name to the user profile. The profile is a CPT however. The URL consists out of the users firstname + lastname + userID.
I need help in creating a user link for outside of the freelancer view. So that when a user is clicked their profile is shown (just like a regular author page).
TL;DR
1. Created a custom post type called freelancers which serves as a profile post for users
2. Need a link that points to the individual users profile page.
Okay so you need a link to the Freelancer single post page, and you want to display the link on the template for a single Offer or in a View of Offers, correct? And Freelancer is not directly related to Offer in any post relationship, correct?
If I'm right about those things, then in the Offer you have information about the User (as author) and you need to translate that information into the URL of the corresponding Freelancer. We offer the wpv-post-author shortcode, which can give you access to any user meta field, including ID, first_name, and last_name: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-author
For example:
[wpv-post-author format='meta' meta='ID']
[wpv-post-author format='meta' meta='first_name']
[wpv-post-author format='meta' meta='last_name']
You could use those pieces of information to construct a custom link href in whatever format you want:
<a href="/freelancer-slug/[wpv-post-author format='meta' meta='ID']... ... .../">Freelancer Name</a>
Will that work?
Okay so you need a link to the Freelancer single post page, and you want to display the link on the template for a single Offer or in a View of Offers, correct? And Freelancer is not directly related to Offer in any post relationship, correct?
Above is correct. The problem with your solution however is that it grabs the post authors first / last name correctly, but it capitalizes the first and last name within the URL, causing it to not point to the right URL.
So right now:
1. Single job post contains a view called "Offers". These show all offers that has been made through a form on that job post. Offers = a child of Job post.
2. In the view the name of the freelancer is shown alongside some extra information. With your solution I created a custom link to the users single freelancer post: Profile.
3. This does grab the author of the offer but it capitalizes the letters.
Should I create a relationship between freelancer / offer aswell? Currently offer is a child of job post, because the offer has to be made within the job post, would this make it easier?
Okay I see what you mean. You could use a post relationship if you'd like. Or if the post author of the Offer is the same as the post author of the Freelancer post, there is a simpler solution:
- Create a View of Freelancers filtered by post author, where the post author is the same as the author of the current post in the loop (see the screenshot here for a Query Filter example).
- In the Loop of this View, insert a post link shortcode.
- Place this View of Freelancers inside the loop of the View of Offers.
- Create a View of Freelancers filtered by post author, where the post author is the same as the author of the current post in the loop (see the screenshot here for a Query Filter example).
- In the Loop of this View, insert a post link shortcode.
- Place this View of Freelancers inside the loop of the View of Offers.
Great! This did exactly what was needed, thanks!
My issue is resolved now. Thank you!