Hey Bricks-Community!
I just switched from Elementor to Breakdance and finally arrived at bricks. Normally, I manage to figure out everything with a simple search, but I spent about 8 hours trying to archive the following without success.
Setup & Goal:
I have ACF with a User-Relationship field for Single Posts
For each Post there is the normal Author (from Wordpress) and I select 1-3 Users via the ACF Field, that contributed to the post
I want to display a post loop of the contributing authors in my Single Post Template
Problem(s):
If I create a block with a query loop inside and select Users, I get all users the blog has and not only the ones I linked with my ACF. I probably have to define the field somehow, so it only uses the users that I have selected, but I don’t know how.
Even with a list of all my pages users, I don’t manage to link to their archive page. If I try something like: “https://my.blog/author/{wp_user_login}/” I just get the link to my single post author. Is this a bug?
ChatGPT to the rescue. It managed to put all this in a php block.
I’m showing this to you, because it might help you to understand my goal. My question is now: How do I do this with bricks instead of the php block?
<?php
$users = get_field('single_reviewed-user');
if( $users ):
// Get the first user object from the array
$user_obj = $users[0];
if (is_a($user_obj, 'WP_User')) {
// User ID
$user_id = $user_obj->ID;
// User Info
$user_info = get_userdata($user_id);
if ($user_info) {
// User info is available
?>
<div class="user-info">
<h3><?php echo esc_html($user_info->display_name); ?></h3>
<div class="user-avatar">
<?php echo get_avatar($user_id); ?>
</div>
<a href="<?php echo get_author_posts_url($user_id); ?>">View all posts by this user</a>
</div>
<?php
} else {
// User data not found
echo '<p>User not found.</p>';
}
} else {
// User object not valid
echo '<p>Invalid user data.</p>';
}
else:
// No user selected
echo '<p>No user selected.</p>';
endif;
?>