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?


Ok, I managed to get it working but I think this function is running all my parent pages with childeren so maybe a bit of an overload?

Is there a way to only check the page_ID(of the parent) and his childeren for the page where the review is submitted?

This is what I got now:

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',
            '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
    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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.