Home › Forums › Add-ons › Repeater Field › How Create Repeater Function
Hi,
I’m not great at creating functions, especially for the repeater field.
I have a repeater field named “myPresto_player”
with 2 text sub_fields: “presto_time” and “presto_topic”
Here is code the Presto Player developer advised I used to display the videos timestamp & optional content:
$timestamp = get_field('timestamp_field');
$optional_text = get_field('optional_text_field');
echo do_shortcode ('[pptime time="' . esc_attr($timestamp) . '"]' . esc_html($optional_text) . '[/pptime]');
Here is the function I have written for a repeater field using the above code:
function display_presto_content() {
if( have_rows('my_presto_player') ):
while( have_rows('my_presto_player') ) : the_row();
$timestamp = get_sub_field('presto_time');
$optional_text = get_sub_field('presto_topic');
if (!empty($timestamp)) {
// Build the shortcode with the timestamp and optional text
$shortcode = '[pptime time="' . esc_attr($timestamp) . '"]' . esc_html($optional_text) . '[/pptime]';
echo do_shortcode($shortcode);
}
}
First off, I’m not sure I have written the function correctly. Also, I’m not sure how to display the fields in a post.
Would greatly appreciate help with this.
Continuing from your other post:
add_shortcode('showpptime', 'display_presto_content');
function display_presto_content($atts=array, $content='') {
$value = '';
if( have_rows('my_presto_player') ):
while( have_rows('my_presto_player') ) : the_row();
$timestamp = get_sub_field('presto_time');
$optional_text = get_sub_field('presto_topic');
if (!empty($timestamp)) {
// Build the shortcode with the timestamp and optional text
$shortcode = '[pptime time="' . esc_attr($timestamp) . '"]' . esc_html($optional_text) . '[/pptime]';
$value .= do_shortcode($shortcode);
}
return $value;
}
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.