WordPress.org

Ready to get started?Download WordPress

Forums

Simple Fields
[resolved] Getting images in repeatable fields (3 posts)

  1. sugardaddy
    Member
    Posted 1 year ago #

    Hi !
    I thought I was right with this code :

    <?php
    $major_features = simple_fields_values("major_feat_title,major_feat_image,major_feat_link,major_feat_anchor");
        foreach ($major_features as $major_feature) {
            $file_id = simple_fields_value('major_feat_image');
            $image_info = wp_get_attachment_image_src($file_id, "full");
            $image_url = $image_info[0];
            $post_id = simple_fields_value('major_feat_link');
            $post_url = get_permalink($post_id);
            echo "<li style='background-image: url($image_url)'><p>" . $major_feature["major_feat_title"] . "</p><a href='$post_url#" . $major_feature["major_feat_anchor"] . "'>" . __('En savoir plus',superprotobeef2) . "</a></li>";
        }
    ?>

    But I get only the image of the first occurrence repeated for each...

    Thanks for your help !

    http://wordpress.org/extend/plugins/simple-fields/

  2. Pär Thernström
    Member
    Plugin Author

    Posted 1 year ago #

    You should have all your info in the variable $major_feature in each loop already, so in the loop you should be able to do:

    $file_id = $major_feature["major_feat_image"];
    $post_id = $major_feature["major_feat_link"];
  3. sugardaddy
    Member
    Posted 1 year ago #

    That does the trick !!
    Thanks a lot.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic