フォーラムへの返信

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック投稿者 oga111

    (@oga111)

    MIZUNO様のご助言で、問題は解決したのですが、
    上記、ソースですと、メインループに影響が出てしまいましたので、
    念のため、正しいソースを掲載しておきます。
    wp_reset_postdata(); を追加しました。

    function my_acf_load_field_abcde( $field ){
    $field[‘choices’] = array();
    $the_args = array(‘post_type’ => ‘●●’);
    $the_query = new WP_Query($the_args);
    while ( $the_query->have_posts() ) : $the_query->the_post();
    $field[‘choices’][ $the_query->post->ID ] = $the_query->post->post_title;
    endwhile;
    wp_reset_postdata();
    return $field;
    }
    // v4.0.0 and above
    add_filter(‘acf/load_field/name=abcde’, ‘my_acf_load_field_abcde’);

    トピック投稿者 oga111

    (@oga111)

    Fumito MIZUNO 様

    ありがとうございます!
    バージョンが4.0だったので、以下記述に変更することで解決しました。
    // v4.0.0 and above
    add_filter(‘acf/load_field/name=color’, ‘my_acf_load_field’);

    なんと、初歩的なミスで大変申し訳ございません。
    この度はありがとうございました!!!

2件の返信を表示中 - 1 - 2件目 (全2件中)