Skip Navigation

[Gelöst] link to posts in custom field

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created vor 8 Jahre, 11 Monate. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 Antworten, has 2 Stimmen.

Last updated by zoeS vor 8 Jahre, 11 Monate.

Assisted by: Waqas.

Author
Artikel
#301426

I am trying to: Add a custom field for the post type "testimonials" that will allow the user to make a link to a post of the type "practitioner". I could use the URL field type, but wondered if it's possible without copying and pasting the URL from the front end? The site is for a therapy centre with many different therapies and practitioners. We want to be able to link the testimonials to the practitioners.

#301464

Waqas
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

Can you please explain that what kind of data you are storing in the custom field, for linking purposes? For example, a Post ID, Post Title or etc (of practitioner post type).

This way I can offer you more appropriate solution.

#301472

Ultimately, I will want it to be output in the front end as a link to the profile page of the appropriate practitioner (website.com/practitioners/their-name). So there will be a testimonials page that loops through each post of the type "testimonials", displaying the quote itself, plus the name of the practitioner to whom the quote refers, and a link to their profile.

My objective is to make it easy for my client to make the link to the practitioners when they are adding the testimonials, so at present I have one field for the name, and another where they just paste in the URL, as copied from the front end). That will work fine, but I just wondered if there's any way for them to be able to select the practitioner from an automatically populated dropdown list. Now that I'm writing it down, I realise it's not very likely! Though I suppose if they were to enter just the practitioner's name (correctly!), I could then use that to get the URL. Thank you

#301781

Waqas
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for explaining, I understand now. There are apparently 2 ways to make it easy for a person entering the data. Please consider followings:

A) You can make practitioner, a parent of Testimonials CPT. This way, when you will be adding a new testimonial in the WP Admin, you will see a drop down list, showing all practitioners. So you can select the right one. And on your Testimonials View, you can use [wpv-post-link id="$parent"] to show the title of the Practitioner linked to her page. This option however requires some understanding about Post Relationships, please see https://toolset.com/documentation/user-guides/creating-post-type-relationships/ for more information.

B) The other option does not require any kind of relationship, and is quite straight forward. But user must always type in the "exact" name of practitioner as it was entered for her post title. This requires to add following code in your theme's functions.php file:

function get_practitioner_link($atts) {
	$title = $atts["title??];
	$practitioner = get_page_by_title($title);

	return get_permalink($practitioner->ID);
}
add_shortcode("link-practitioner??, "get_practitioner_link??);

And use it in your Testimonial View as below:

<a href="[link-practitioner title='[wpv-post-field name="wpcf-practitioner"]']">[wpv-post-field name="wpcf-practitioner"]</a>

Please carefully notice the nesting of [wpv-post-field] in [link-practitioner] short code. Also remember to register [link-practitioner] short code in Views -> Settings -> Third-party shortcode arguments section. Further, replace "wpcf-practitioner" with appropriate name of custom field, used to store practitioner name (with a testimonial).

I hope adopting any of these will help resolving this issue. Please let me know if I can help you with anything related.

#301814

Wow, what incredible support! Thank you so much, either one of these solutions should work very well for me, so I'll weigh up the pros and cons and definitely use one.

Das Forum „Types Community Support“ ist für neue Themen und Antworten geschlossen.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.