Hi everyone! I’ve been using ACF for years without any problem, but now I have to do something too difficult for my abilities and I need some help, I’ll try to explain:
I have a CPT named ‘Authors’, that has several Custom Fields and a Relationship with Users. I want to link each cpt-Author to a User and basically add Author informations every time a User is shown.
Now I’m trying to achieve two things:
– In every (standard) Post page where user info are show, add the custom fileld infos from the Author cpt… is this possible?
– In every Author page, retrieve all the posts from the assigned user.
I hope I made myself clear, I dunno if there was an easier way, this is the only way I found, but still I’m stuck and don’t know where to start…
you need a relationship field at user or/and at author.
because you should be able to query relationship fields in both directions. you can
show users at author page, and show author details at user page (at least if users and authors are CPTs)
but to get it working you need advanced php/ACF/WP knowledge. if you are unable to adapt the example for your needs, you probably need to hire someone to do it for you.
Hi! thanks for the answer. I tryied some more but with poor results, it seems wp documentation on users and query is a bit overlooked…
Where can I find someone to hire some help? Do you have any ideas?
I’m from Italy and I don’t know anyone capable of doing that…
This is absolutely possible to do and it’s really just a basic relationship querying and reverse querying.
These two different queries should get you going! If you need further extensive help you can contact me directly at [email protected] for help through our web agency.
//This should be in the loop //Fetch an author post based on the current post authors (users) ID $author_ID = get_the_author_meta('ID'); $args = array( 'post_type' => 'authors', 'meta_query' => array( array( 'key' => 'userfieldname', 'value' => $author_ID, 'compare' => 'LIKE' ) ) ); $author_query = new WP_Query($args); //fetch all posts for the user. I'm not 100% sure the user field type returns an user object but I think so. //It's also possible that $author is an array with user objects inside. if so change $author->ID to $author->ID. $author = get_field('userfieldname'); $args = array( 'post_type' => 'authors', 'author' => $author->ID ); $usersposts_query = new WP_Query($args);
You must be logged in to reply to this topic.
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!
© 2023 Advanced Custom Fields.