dtcu5885 2018-01-31 20:09
浏览 56
已采纳

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

hello experts i have been trying to retrieve data from fields that i created enter image description here

the field name is "ddw" and its repeater and enter image description here

its subfield op1 and it has lots of rows enter image description here

but i am still not able retreive any row by using this code

<?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;
?>

and it finds no row . i want all rows from every posts and particularly i want http links to put on array and loop through it . i have put this script in wp directory its not theme or template folder. please help me where i am doing wrong .thanks in advance

  • 写回答

1条回答 默认 最新

  • dongyi7966 2018-02-01 08:00
    关注

    For your code to work, it should look like this. (replace $post_id with your post id variable)

    <?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;
    ?>
    

    You can find code samples here for all scenarios like without loop or for all posts with post ID. Try https://www.advancedcustomfields.com/resources/code-examples/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line