WordPress「Favorites」のお気に入り一覧でACFの画像を出力する

Filed under: php,wordpressプラグイン — kdcs @ 20年8月12日 水曜日

WordPress お気に入りプラグイン「Favorites」のお気に入り一覧ページに
ACF(アドバンスドカスタムフィールド)を出力させる

一覧ページにACFの画像を出力
カスタムフィールド名:02item-image1

<?php 

$favorites = get_user_favorites();

    if (isset($favorites) && !empty($favorites)) :
      foreach ($favorites as $post_id) :
$p = get_post($post_id);

    $attachment_id1f = get_field('02item-image1' , $post_id );
    $size1f = "large"; // (thumbnail, medium, large, full or custom size)
    $image1f = wp_get_attachment_image_src( $attachment_id1f, $size1f );
    $attachment = get_post( get_field('02item-image1') );
    $alt1 = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
    $image_title1 = $attachment->post_title;

        echo '<div>' . get_the_title($post_id) . get_favorites_button($post_id) . '</div>';
        echo '<img src=' . $image1f[0] . '>';
      endforeach;
    else :
      // No Favorites
      echo '<p class="text-center">お気に入りがありません。</p>';
    endif; ?>

サイト内検索

カテゴリー

最近の投稿

« |WordPress「Favorites」のお気に入り一覧でACFの画像を出力する| »
↑上に戻る