Home › Forums › General Issues › Share Field Values Across Pages › Reply To: Share Field Values Across Pages
// 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.
usefull links:
WP_Query
WP_User_Query
acf/save_post
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.