php - Wordpress ACF php 关系
问题描述
我整天都在阅读论坛,我正在努力想出解决这个问题的方法。
我有 2 种自定义帖子类型:人员职位
使用 ACF 关系,我有一个名为 Job Client (job_client) 的 2 向关系字段,我们可以将相关的客户/客户链接到作业。
我想在工作页面上显示的是从“人员”自定义帖子类型中提取的客户的一些基本信息。雇主、联系方式等。这些设置为 ACF 字段。
到目前为止,我已经得到了以下代码。它可以很好地显示标准的 wordpress 字段(标题、永久链接),但我在 ACF 字段上苦苦挣扎。任何帮助/建议将不胜感激。
<?php
$job_client_connect = get_posts(array(
'post_type' => 'people',
'meta_query' => array(
array(
'key' => 'job_client', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));
?>
<?php if( $job_client_connect ): ?>
<table>
<?php foreach( $job_client_connect as $job_client_connect ):?>
<tr>
<td>
<a href="<?php echo get_permalink( $job_client_connect->ID ); ?>">
<?php echo get_the_title( $job_client_connect->ID ); ?>
</a>
<p><?php echo get_field('employer', $job_client_connect->ID ); ?></p>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
解决方案
任何可能觉得这很有用的人的完整工作代码
<?php
$job_client_connect = get_posts(array(
'post_type' => 'people', // name of post type
'meta_query' => array(
array(
'key' => 'job_client', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));
?>
<?php if( $job_client_connect ): ?>
<table>
<?php foreach( $job_client_connect as $job_client_connect ):?>
<?php $employer = get_field('employer', $job_client_connect->ID ); ?>
<tr>
<td>
<a href="<?php echo get_permalink( $job_client_connect->ID ); ?>">
<?php echo get_the_title( $job_client_connect->ID ); ?>
</a>
<p><?php echo $employer[0]->post_title; ?></p>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
推荐阅读
- javascript - 在 AJAX 请求中单击图标时声明事件
- nginx - Nginx:如果 Nginx 没有运行,如何启动 Nginx?
- vue.js - vue的render函数中的slot是什么意思
- node.js - 如何修改请求正文
- php - 无法在 nginx 服务器上上传大于 6 mb 的图像
- python - 用户定义的模块找不到顶级变量和模块
- json - 只读文件系统:“data.json”:aws lambda 函数中的 IOError
- css - 我的导航栏的宽度没有使用 CSS 占据屏幕的 100%?
- javascript - Javascript 列表和数组索引
- javascript - 在 javascript 中检索 Array.map 的结果