以下为示例代码:
// example ACF field setup add_action('acf/init', 'my_acf_init'); function my_acf_init() { acf_add_local_field_group(array( 'key' => 'group_5ff6d5226e932', 'title' => 'My Group', 'fields' => array( array( 'key' => 'field_5ff6d5e5e97d4', 'label' => 'My Field', 'name' => 'my_field', 'type' => 'text', ), ), 'location' => array( array( array( 'param' => 'post_type', 'operator' => '==', 'value' => 'post', ), ), ), )); }
// example usage in theme file $my_field = get_field('my_field', get_the_ID()); if ($my_field) { echo $my_field; }
// example usage with get_field() $my_field = get_field('my_field', get_the_ID()); if ($my_field) { echo $my_field; }
// example usage with the_field() if (have_rows('my_repeater_field', get_the_ID())) { while (have_rows('my_repeater_field', get_the_ID())) { the_row(); the_field('my_sub_field'); } }
// example usage with correct field name and location $my_field = get_field('my_field', get_the_ID()); if ($my_field) { echo $my_field; }
// example usage with rich text editor $my_field = get_field('my_rich_text_field', false, false); if ($my_field) { echo $my_field; }