figured out the issue, i had to change the following code from…
<?php $posts = get_field('agent'); if( $posts ): ?>
<div class="agents">
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
to this code….. basically $posts in this section to $agent
<?php $agent = get_field('agent'); if( $posts ): ?>
<div class="agents">
<?php foreach( $agent as $p ): // variable must NOT be called $post (IMPORTANT) ?>
Thank you @smspaul I have been racking my brain on this!
Hi @elliot
I have placed that code and this is my outcome…
Array
(
[numberposts] => -1
[post_type] => caregiver-updates
[meta_key] => user_id
[meta_value] => 3
)
This is what I have so far and its not pulling any posts…
<?php
// args
$args = array(
'numberposts' => -1,
'post_type' => 'caregiver-updates',
'meta_key' => 'user_id',
'meta_value' => $current_user->ID
);
// get results
$the_query = new WP_Query( $args );
// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
Hey @elliot
I really don’t need a multi-select, I can change that. If it were a single selection could you provide me with the code to do what I’m needing? I thank you so much for all your help!!!
Hi @elliot
I have looked over the links you sent as well as researched but I’m having trouble putting it all together, I know how to code into my templates just not having luck getting the code right to do the following…
Page is called Updates and shows custom post types ‘caregiver-updates’, I have it working fine now that it shows ALL the posts… but I want to only show the posts that are assigned to the logged in user by using the Advanced Custom Field User ‘user_id’, it needs to be dynamic incase a new user is created.
See Screen shot of the Advanced Custom Field “User(s) to Share this Update” has the Field name of ‘user_id’
Front end URL to this page is http://caretocontinue.staging.wpengine.com/caregiver-updates/
Thanks Elliot, however I’m having a really difficult time putting this all together, my custom post type is ‘caregiver-updates’ and the advanced custom field that selects the user name is ‘user_id’…
What I need to happen is if the user is logged in it will show all the custom post types of ‘caregiver-updates’ that have the advanced custom field user name ‘user_id’ selected, so somehow check if current user id logged in matches the custom field ‘user_id’ and then pull just those posts, please advise. Thank you so much!!!!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.