Home › Forums › ACF PRO › Save/update field of custom field with function › Reply To: Save/update field of custom field with function
Ok, I got it working but I think with this function he is checking every parent page with his childeren or not?
Is there a way to only trigger everything for the parent and his childeren on the page where the review is submitted?
This is the function I currently have:
function rex_my_action ($review, $post_id) {
// Set up the objects needed
$hosting_provider_query = new WP_Query();
global $post;
$hosting_pagina_titel = $post->post_title;
$doorzoek_alle_paginas = $hosting_provider_query->query(array(
'post_type' => 'page',
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'naam_hosting_provivder',
'value' => $hosting_pagina_titel,
'compare' => '='
),
),
));
// Filter through all pages and find Page's children
$alle_child_paginas_doorlopen = get_page_children( get_the_ID(), $doorzoek_alle_paginas );
// echo what we get back from WP
if(!empty($alle_child_paginas_doorlopen)){
foreach($alle_child_paginas_doorlopen as $pakket_hp){
$id_tonen = $pakket_hp->ID;
$postid = get_queried_object_id();
$some_value = get_post_meta( $postid, 'rwp_user_score', true );
update_field('gemiddelde_score_hosting_provider', $some_value, $id_tonen);
}
}
}
add_action( 'template_redirect', 'rex_my_action' );
add_action('rwp_after_saving_review', 'rex_my_action', 11, 2);
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.