Home › Forums › ACF PRO › Save/update field of custom field with function › Reply To: Save/update field of custom field with function
Thanks for your answer but this is not what I meant.
The meta value (rwp_user_score) of the parent page is updated when this function is being executed. When a user submits a new review this value is updated automaticly.
Only the custom field (gemiddelde_score_hosting_provider) of all the child pages of the parent are getting the value from the parents meta value (rwp_user_score). This value gets stored in the custom field (gemiddelde_score_hosting_provider).
The current function is doing this:
– Get all pages where custom field value of naam_hosting_provivder equals the post_title
– Then get all childs of this pages
$alle_child_paginas_doorlopen = get_page_children( get_the_ID(), $doorzoek_alle_paginas );
– in the for each loop store every child page ID in a variable
$id_tonen = $pakket_hp->ID;
– then get the Page ID of the parent
$postid = get_queried_object_id();
– then get the meta ‘rwp_user_score’ of parent page (ID)
$some_value = get_post_meta( $postid, 'rwp_user_score', true );
– and finaly update the field where it is al about
update_field('gemiddelde_score_hosting_provider', $some_value, $id_tonen);
My coding skills are not that great but I think this function is looping through every page and its childs. When the site goes online we expect to have over 100 parent pages and each parent has over 10 child pages.
So I think it is a bit of an overkill to loop and update the field (gemiddelde_score_hosting_provider) of every child page if only one meta value of a parent gets updated.
While I am explaining this, I can clearly understand that it is not very clear what I am trying to achieve. Maybe it’s useful if I write it off completely.
On a page, a user can leave a review. The average score is stored in the post_meta under ‘rwp_user_score’ of this page.
Each page represents a hosting provider and each hosting provider has packages. Each package is a child of a hosting provider page and has a custom field called “gemiddelde_score_hosting_provider”.
The average score stored in the post_meta of the hosting provider page I put in the custom field “gemiddelde_score_hosting_provider” for each package of this hosting provider.
This is all done when a new review submitted.
Only with the current function, all custom fields of the child pages of each parent page are updated again.
This is a bit redundant as he only has to update the custom fields of the child pages of the parent page where a review is submitted at that moment.
Is it possible to realize this with my current function?
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.