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 support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

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

Last updated by Christian Cox 6 years, 7 months ago.

Assisted by: 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"]

  • [types field='wpcf-medias' alt='%%ALT%%' title='%%TITLE%%' size='large' align='none' resize='proportional' separator=', '][/types]
  • [/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/