【发布时间】:2021-06-15 22:00:11
【问题描述】:
我想查询: 我在“评估”CPT 中有一个条目,其中包含使用 ACF 制作的自定义字段,其中之一是名称“客户”,其中包含客户 ID。 我想知道如何在前端显示另一个名为“客户”的 CPT 字段。 我也用 ACF 做的自定义字段名为“profile_photo”。此CPT的作者与“assessment”CPT中的ACF自定义字段“customer”相同。
我认为它会是这样的......我不知道我是否走在正确的轨道上。
function the_field_by_author( $field, $author ) {
$user_info = get_field( "customer" );
$args = [
'post_author' => $user_info->ID,
'post_type' => 'clientes',
'post_status' => 'publish',
'posts_per_page' => 1
];
$my_post = get_posts( $args );
if( $my_post ) {
return get_field( "photo_profile", $my_post->ID );
}
}
add_shortcode('shortcode_the_field_by_author', 'the_field_by_author');
我是新手,不知道如何在每个“评估”条目中显示自定义字段。 非常感谢您。
【问题讨论】:
-
Manuel 请参阅stackoverflow.com/help/how-to-ask。您可以从 SQl 查询开始以实现上述目标。
标签: wordpress