Is it possible to share field group values across posts/pages?
For instance, with a competition schedule:
There are Event Pages, with a line-up of performers. Each performance has a time, performer, and ranking (added later).
Event Z: 2:15 – Performer A – ***** / 2:30 – Performer B – ***
There are also Performer pages, which lists which events they go to. Performers may attend multiple events. Rankings get added to performer pages after the event.
Performer A: Event Y: ** / Event Z: *****
Is it possible to create relationships between fields across posts types/pages, to relate the data so once I add information to Event Z, I don’t have to go back and add it to the associated Performers?
// current post global $post; // args for query $query_args = array( 'post_type' => 'performers', // performers post_type (or use WP_User_query for users) 'meta_query' => array( array( // performers match field slug 'key' => 'event_id', // field slug acf (use post object field and return id) 'value' => $post->ID // current post id ) ) ); // set wp query $query = new WP_Query( $query_args ); // query have posts if( $query->have_posts() ): // loop posts (performers) while( $query->have_posts() ): $query->the_post(); // update fields you like // field_slug, field_value, current perfomers id update_field( 'YOUR_FIELD_SLUG', 'YOU_FIELD_VALUE', get_the_ID() ); // end loop endwhile; // reset query wp_reset_postdata(); // end endif;
I do not know if I understood you correctly, but I’m thinking (depending on your own needs) that you should reach your goal.
You can also put that into a function and then use it the way you need it everywhere.
If you want to do this via / wp-admin, you should look at acf/save_post and combine it.
Thanks for your response. I’m not sure I fully understand the above, but my design and needs have changed, and I’m getting closer to understanding what I need… and maybe you can help again?
This code will be on a Band Page, calling to a Competition Page. Each have repeaters… band repeats competition list, competition repeats band and scores. I want to call a specific band’s scores from the competition page. I’m not sure how to specify the repeater row.
$post_object = get_sub_field(‘competition’);
if( $post_object): $post = $post_object;
setup_postdata( $post ); ?>
if( have_rows(‘competition_schedule’) ):
while ( have_rows(‘competition_schedule’) ) : the_row();
// no rows found
<?php wp_reset_postdata(); ?>
<?php endif; ?>
But right now, each band is pulling the same score.
While I haven’t touched a template yet for the competitions in this regard, “State fight” does have both New Bund and Three Bund as in there, within the repeater, with different scores.
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!
© 2022 Advanced Custom Fields.