Advanced Custom Fields dynamic update_field

I have a function that is triggered when a new review is submitted on a specific page.

function rex_my_action ($review, $post_id) {

$some_value = get_post_meta( 753, ‘rwp_user_score’, true );
update_field(‘gemiddelde_score_hosting_provider’, $some_value, 763);

}
add_action(‘rwp_after_saving_review’, ‘rex_my_action’, 11, 2);

When this happens an advanced custom field is updated with the parent_post meta_value rwp_user_score.

The code above is working but I have to fill out the parent Page-ID (753) and child-ID (763) manualy.

I have this page structure:

Parentpage 1

Childpage 1
Childpage 2
Childpage 3

Parentpage 2

Childpage 1
Childpage 2
Childpage 3

Etc. Etc.

I think I have to create a for each loop or something because there are more Childpages in a Parent.

So that for each childpage the field ‘gemiddelde_score_hosting_provider’ gets updated.

Maybe something like this?

$some_value = get_post_meta( $post->post_parent, ‘rwp_user_score’, true );

Get all pages with meta_key rwp_user_score but after that I am a bit lost.

What I want is that every child-page with the field ‘gemiddelde_score_hosting_provider’ gets updated with the value of his parent meta_key ‘rwp_user_score’. Manualy I got it working but it would be nice if it can be done dynamicly.

Anybody got a clue?

Read more here:: Advanced Custom Fields dynamic update_field

Leave a Reply

Your email address will not be published. Required fields are marked *