How to add dynamically the main parent pages’s custom fields and their values to all sub-pages?
The parent post ID is stored in $post->post_parent. So you can access the parent data by using that ID in get_post_meta(). To get the ancestors use get_post_ancestors( $post->ID ). It returns an array of parent IDs, the last one is the highest. Let’s invent a helper function for the next examples: if ( ! function_exists( … Read more