Php 按用户列出的ACF关系字段
试图查询在用户关系字段中设置了当前用户的帖子。我以为这很容易,但我完全被卡住了。 我试过这个:Php 按用户列出的ACF关系字段,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,试图查询在用户关系字段中设置了当前用户的帖子。我以为这很容易,但我完全被卡住了。 我试过这个: <?php $user = new WP_User(get_current_user_id()); $posts = get_field('consultora', 'user_'.$user->ID); if( $posts ): ?> <div class="assistente-foto"> <?php fo
<?php
$user = new WP_User(get_current_user_id());
$posts = get_field('consultora', 'user_'.$user->ID);
if( $posts ):
?>
<div class="assistente-foto">
<?php foreach( $posts as $post):?>
<?php setup_postdata($post); ?>
<?php echo the_post_thumbnail();?>
<p><strong><?php echo get_the_title(); ?></strong></p>
<p>t. <?php the_field('telefone'); ?></p>
<p>e. <?php the_field('email'); ?></p>
<?php endforeach; ?>
</div>
<?php wp_reset_postdata();?>
<?php endif; ?>
t
e
因此,您的用户配置文件中有一个关系字段(ID为:“consultora”),您希望查询该字段。$posts是否包含所需的数组?(那么您是通过get_field()获取数据的吗?)当您在WP中查找用户数据时,您应该检查用户是否已登录-因此我会将整个内容放入is_user_logged_in()条件中-以确保我应该获取用户数据。