Problem: I am using a shortcode from the e2PDF plugin that displays a Types custom field value. However, my field allows multiple instances and I would like to display one specific index of that field. How can I customize the shortcode to work with Types repeating field values?
Solution: Response from e2PDF support:
As for now you can try to hook default output with adding filter to your theme functions.php:
add_filter('e2pdf_model_shortcode_e2pdf_wp_response', 'e2pdf_toolset_types_repeater', 10, 3); function e2pdf_toolset_types_repeater($response, $atts, $value) { if (isset($atts['key']) && $atts['key'] == 'wpcf-listing-photo' && isset($atts['index'])) { $id = isset($atts['id']) ? $atts['id'] : false; // Post ID $index = $atts['index']; // Index attribute $field = str_replace('wpcf-', '', $atts['key']); // Converting field key to slug needed for Tooset Types if ($id) { //php function to render value $response = types_render_field($field, array("post_id" => $id, "size" => "thumbnail", "index" => $index)); } else { $response = ''; } } return $response; }
After adding function you must be able to use shortcode as follows:
[e2pdf-wp key="wpcf-listing-photo" meta="true" index="0"] [e2pdf-wp key="wpcf-listing-photo" meta="true" index="1"]
and so on...
For correct usage "types_render_field" function must return "empty" value in case index not exists or url for image if image found, so maybe it will be need to add some parameters to "types_render_field". Unfortunately we can't test it on our side as we do not have yet access to Toolset Types plugin.
Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/
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 3 replies, has 2 voices.
Last updated by 4 years, 1 month ago.
Assisted by: Christian Cox.