Skip Navigation

[Resolved] Link to CPT user profile

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a custom post type "Freelancers" that represents Users. Each User is the author of one Freelancer post. I also have Jobs and Offers as custom post types in a one-to-many post relationship where Jobs is the parent and Offers are the children. Freelancer Users can submit Offers to Jobs. In the Jobs post, I would like to display a list of Offers and a link to the Offer author's Freelancer post.

Solution: Use a nested View setup.
- Create a View of Offers using a post relationship filter, where the parent Job is set by the current post. Insert this View in the Job template.
- Create a View of Freelancer posts, filtered by post author, where the author is the same as the current post in the loop. In the loop output, insert a post link shortcode.
- Insert the View of Freelancer posts in the loop of the View of Offers.

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by amarildow 5 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1283135

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.

#1283267

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?

#1283291

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?

#1283329
Screen Shot 2019-07-03 at 11.05.33 AM.png

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.

#1283387

- 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!

#1283389

My issue is resolved now. Thank you!