如何使用PHP从自定义邮政类型WordPress检索数据

发布于 2025-02-04 20:12:02 字数 1535 浏览 4 评论 0 原文

并且在每列IE(持续时间,incall,outcall,outcall)下方显示的值遇到困难

我正在尝试显示表中插入自定义帖子类型的数据, 。

​“ https://i.sstatic.net/gejz5.png” rel =“ nofollow noreferrer”>

                <table class="rates-table">
                <?php $get_rates_list = get_field('rates_optional');
                        if(get_rates_list){
                            foreach($get_rates_list as $rate){?>
                    <thead>
                        <tr>
                        <td><h3 class="inside-model-single">Duration</h3></td>
                        <td><h3 class="inside-model-single">Incall</h3></td>
                        <td><h3 class="inside-model-single">Outcall</h3></td>
                        </tr>
                    </thead>
                    <tbody>
                            
                            <tr>
                            <td></td>
                            <td><span class="rate_value"><?php echo $rate['incall_1_hour'];?></span></td>
                            <td><span class="rate_value"><?php echo $rate['outcall_1_hour'];?></span></td>
                          </tr>
                        <?php }
                        }?>

                        </tbody>
                    </table>

I'm trying to show the data inserted into custom post types in a table and I'm having trouble showing values in front end underneath each column i.e (Duration, Incall, Outcall)

enter image description here

enter image description here

                <table class="rates-table">
                <?php $get_rates_list = get_field('rates_optional');
                        if(get_rates_list){
                            foreach($get_rates_list as $rate){?>
                    <thead>
                        <tr>
                        <td><h3 class="inside-model-single">Duration</h3></td>
                        <td><h3 class="inside-model-single">Incall</h3></td>
                        <td><h3 class="inside-model-single">Outcall</h3></td>
                        </tr>
                    </thead>
                    <tbody>
                            
                            <tr>
                            <td></td>
                            <td><span class="rate_value"><?php echo $rate['incall_1_hour'];?></span></td>
                            <td><span class="rate_value"><?php echo $rate['outcall_1_hour'];?></span></td>
                          </tr>
                        <?php }
                        }?>

                        </tbody>
                    </table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

同展鸳鸯锦 2025-02-11 20:12:02

一种方法是通过其 name 单独显示 get_field() the_field()

<table class="rates-table">
  <?php $incall_1_hour = get_field('incall_1_hour'); ?>
  <thead>
    <tr>
      <td><h3 class="inside-model-single">Duration</h3></td>
      <td><h3 class="inside-model-single">Incall</h3></td>
      <td><h3 class="inside-model-single">Outcall</h3></td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td></td>
      <td><span class="rate_value"><?php echo $incall_1_hour; ?></span></td>
      <td><span class="rate_value"><?php the_field('outcall_1_hour'); ?></span></td>
    </tr>
  </tbody>
</table>

第二种方法是使用 get_fields()具体帖子。以下只是一个简单的例子,因为我不知道您帖子的完整结构。相应地进行更改。

<?php $get_rates_list = get_fields();

if ($get_rates_list) {
  foreach($get_rates_list as $rate) {
    ?><td><span class="rate_value"><?php echo $rate;?></span></td><?php
  }
} ?>

One way is displaying by its Name individually using get_field() or the_field().

<table class="rates-table">
  <?php $incall_1_hour = get_field('incall_1_hour'); ?>
  <thead>
    <tr>
      <td><h3 class="inside-model-single">Duration</h3></td>
      <td><h3 class="inside-model-single">Incall</h3></td>
      <td><h3 class="inside-model-single">Outcall</h3></td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td></td>
      <td><span class="rate_value"><?php echo $incall_1_hour; ?></span></td>
      <td><span class="rate_value"><?php the_field('outcall_1_hour'); ?></span></td>
    </tr>
  </tbody>
</table>

Second way is using get_fields() to get an array of all field values for current or a specific post. Following is just a simple example as I don't know the full structure of your post. Make your changes accordingly.

<?php $get_rates_list = get_fields();

if ($get_rates_list) {
  foreach($get_rates_list as $rate) {
    ?><td><span class="rate_value"><?php echo $rate;?></span></td><?php
  }
} ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文