ACF 使用 wordpress 高级自定义字段插件找不到行

ACF no rows found using wordpress advanced custom field plugin

你好专家我一直在尝试从我创建的字段中检索数据

字段名称是"ddw"及其转发器和

它的子字段 op1 并且它有很多行

但我仍然无法使用此代码检索任何行

<?php 
require_once 'wp-load.php';
require_once ABSPATH . '/wp-admin/includes/taxonomy.php';
include_once 'wp-content/plugins/acf351/acf.php';
// check if the repeater field has rows of data
if( have_rows(get_field('ddw')) ):
    // loop through the rows of data
    while ( have_rows(get_field('ddw')) ) : the_row();

        // display a sub field value
       echo the_sub_field('op1');

    endwhile;
else :
    echo 'no rows found';
endif;
?>

它没有找到任何行。我想要每个帖子的所有行,特别是我想要将 http 链接放入数组并循环遍历它。我已将此脚本放在 wp 目录中,它不是主题或模板文件夹。请帮助我哪里做错了。提前致谢

要使您的代码正常工作,它应该如下所示。 (将 $post_id 替换为您的 post id 变量)

<?php
require_once 'wp-load.php';
require_once ABSPATH . '/wp-admin/includes/taxonomy.php';
include_once 'wp-content/plugins/acf351/acf.php';
// check if the repeater field has rows of data
if( have_rows('ddw' , $post_id) ):
    // loop through the rows of data
    while ( have_rows('ddw', $post_id) ) : the_row();

        // display a sub field value
       echo get_sub_field('op1');

    endwhile;
else :
    echo 'no rows found';
endif;
?>

您可以在此处找到所有场景的代码示例,例如没有循环或所有具有 post ID 的 post。 尝试 https://www.advancedcustomfields.com/resources/code-examples/