php - 从 ACF 字段中检索数据并显示在 Wordpress 的前端表中
问题描述
我想在 index.PHP 中显示一个动态表,每次新条目和显示时都会从 ACF 字段中检索数据。我是 php 新手,不知道确切的方法。这是我的鳕鱼,
<div class="table">
<?php
$args = array( 'post_type' => 'Team', 'posts_per_page' => 20 );
$loop = new WP_Query( $args );
`while ( $loop->have_posts() ) : $loop->the_post();
?>
endwhile
?>
<table class="tb1" style="width:50%">
<tr>
<th > Name</th>
<th >Email</th>
<th >Phon no</th>
<th >Designation</th>
</tr>
<tr>
<td ><?php echo get_field('name');?></td>
<td ><?php echo get_field('email');?></td>
<td><?php echo get_field('phon_no');?></td>
<td><?php echo get_field('designation');?></td>
</tr>
</table>
解决方案
请使用此代码。
<div class="table">
<?php
$args = array( 'post_type' => 'Team', 'posts_per_page' => 20 );
$loop = new WP_Query( $args );
?>
<table class="tb1" style="width:50%">
<tr>
<th >Name</th>
<th >Email</th>
<th >Phon no</th>
<th >Designation</th>
</tr>
<?php
while ( $loop->have_posts() ) : $loop->the_post();
?>
<tr>
<td ><?php echo get_field('name');?></td>
<td ><?php echo get_field('email');?></td>
<td><?php echo get_field('phon_no');?></td>
<td><?php echo get_field('designation');?></td>
</tr>
<?php
endwhile?>
</table>
推荐阅读
- json - 使用 Reactjs、Axios 和本地 JSON 文件的登录过程
- reactjs - i18 文本内的材质 ui 图标
- wordpress - 在具有木材值的树枝模板中设置上下文,
- c# - 实体框架未映射连接
- python - Django Nginx:给出警告:django.request:未找到:运行服务器时
- batch-file - 在批处理脚本中编写一个宏,将另一个库文件批处理中的其他宏加载到内存中
- php - PHP Discord Webhook POST 请求返回字符串(0)
- kotlin - 使用 kotlin 在函数内部返回一个函数(返回一个字符串)
- node.js - 我的测试服务器(连接到测试 PostgreSQL 数据库)没有以 JSON 格式显示数据?
- python - 如何从 HTML 类中获取 href?