Problem:
The user wants to use a URL value contained in an ACF URL field within a Toolset View to create a link with the post title.
Solution:
Create a custom shortcode to retrieve the URL value from the ACF field.
Use the custom shortcode within the Toolset View to generate the link.
Here's an example of a custom shortcode implementation:
add_shortcode('get_url_by_field', 'get_url_by_field_fn'); function get_url_by_field_fn( $atts ) { $data = shortcode_atts( array( 'field' => '' ), $atts ); if(!empty($atts['field']) && $atts['field'] === 'durl') { $url = get_field('durl'); if($url) { return esc_url($url); // Always escape and validate URLs } } }
Usage within the Toolset View:
<p style="font-weight:bold; font-size: 1.3em; margin-bottom: 0;"> <a href="[get_url_by_field field='durl']">[wpv-post-title]</a> </p>
This shortcode retrieves the URL value from the ACF field named 'durl' and generates a link with the post title. Make sure to replace 'durl' with the actual name of your ACF URL field.
Relevant Documentation:
Toolset Views: https://toolset.com/documentation/user-guides/views/
ACF Shortcodes: https://www.advancedcustomfields.com/resources/shortcode/
WordPress Shortcodes: https://developer.wordpress.org/plugins/shortcodes/
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.
This topic contains 5 replies, has 2 voices.
Last updated by 10 months, 2 weeks ago.
Assisted by: Christopher Amirian.