Home › Forums › Front-end Issues › Relationship with Users, CPT and queries › Reply To: Relationship with Users, CPT and queries
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);
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.