Support

Account

Home Forums Add-ons Repeater Field Inserting a Sub Field into JS

Unread

Inserting a Sub Field into JS

  • Hi there,

    I have a script that I need to insert a sub-field value (a FontAwesome icon) into. The script separates the last word from the rest of the sentence (see below). My issue is that my sub-field is inside a repeater (which is inside a group) so it repeats all of the icons for the group. Can anyone think of a way to get only the icon for that one row to show?

    Here is the script for separating the last word
    <script>
    $(document).ready(function() {
    $('.last').each(function(index, element) {
    var heading = $(element);
    var word_array, last_word, first_part;
    word_array = heading.html().split(/\s+/); // split on spaces
    last_word = word_array.pop(); // pop the last word
    first_part = word_array.join(' '); // rejoin the first words together
    heading.html([first_part, ' <span class="last-word">', last_word, '</span>'].join(''));
    });
    });
    </script>

    and here is the code where I am trying to use it
    $link = get_sub_field('featured_item_link');
    if( $link ):
    $link_url = $link['url'];
    $link_title = $link['title'];
    $link_target = $link['target'] ? $link['target'] : '_self';
    ?>
    " target="<?php echo esc_attr( $link_target ); ?>"><?php if ( get_sub_field('featured_item:_background_image') ):
    echo the_sub_field('featured_item:_background_image');
    endif; ?><?php echo esc_html( $link_title ); ?>

    <?php endif; // $link

    Appreciate any and all additional eyes!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.