Skip Navigation

[Resolved] Embed flexslider Code

This thread is resolved. Here is a description of the problem and solution.

Problem: Can I embed Toolset wpv-for-each shortcodes in my PHP templates to loop over repeating fields?

Solution: No, you should use the native WordPress function get_post_meta to get the values of your repeating field, then loop over those values and output the proper HTML strings. This is not a trivial task. Here's a simple example of looping over a repeating image field in PHP:

$string = '';
$medias = get_post_meta(12345, 'wpcf-wpcf-medias', false);
foreach($medias as $img) {
  $string .= "<a href='" . $img . "'><img src='" . $img . "' /></a>";
}
echo $string;

Relevant Documentation:
https://developer.wordpress.org/reference/functions/get_post_meta/

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 1 reply, has 2 voices.

Last updated by Christian Cox 3 years, 8 months ago.

Assigned support staff: Christian Cox.

Author
Posts
#628265

Hi,

I'm using Flexslider for my portfolio, so everything it's working perfectly but the problem is when all post fields are generated they are all of them inside the tag <article></article> and I would like to isolate my portfolio. So I would like to know if it's possible to embed my Portfolio template code directly on my page "single-portfolio.php"?

I have tried to embed this code but it doesn't work :

<div class="flexslider">

<ul class="slides">
[wpv-for-each field="wpcf-wpcf-medias"]

  • <a href="[types field='wpcf-medias' alt='%%ALT%%' title='%%TITLE%%' size='large' align='none' resize='proportional' separator=', '][/types]" classe="img-box img-scale-rotate lightbox">[types field='wpcf-medias' alt='%%ALT%%' title='%%TITLE%%' size='large' align='none' resize='proportional' separator=', '][/types]</a>
  • [/wpv-for-each]

    </div>

    Thank for you help

    #628451

    Hi, Types shortcodes are not meant to be used directly in PHP, they are meant to be used in wp-admin. Instead, you should use the native WordPress function get_post_meta to get the values of your repeating field, then loop over those values and output the proper HTML strings. This is not a trivial task. Here's a simple example of looping over a repeating image field in PHP:

    $string = '';
    $medias = get_post_meta(12345, 'wpcf-wpcf-medias', false);
    foreach($medias as $img) {
      $string .= "<a href='" . $img . "'><img src='" . $img . "' /></a>";
    }
    echo $string;
    

    Here's the documentation for the get_post_meta function:
    https://developer.wordpress.org/reference/functions/get_post_meta/