Skip to content

Instantly share code, notes, and snippets.

@nixonmedia
Last active February 15, 2019 22:18
Show Gist options
  • Save nixonmedia/238db8172e7183df4879bc0ee27401ea to your computer and use it in GitHub Desktop.
Save nixonmedia/238db8172e7183df4879bc0ee27401ea to your computer and use it in GitHub Desktop.
<?php
function set_parent_id($id){
$parent_id = get_field('parent_id', $id);
$args = array(
'posts_per_page' =>1,
'post_type' => 'page',
'meta_query' => array(
array(
'key' => 'entry_id',
'value' => $parent_id,
'compare' => '='
),
)
);
query_posts($args);
while (have_posts()) : the_post();
$wp_parent_id = get_the_id();
update_post_meta($id, 'wp_parent_id', $wp_parent_id);
endwhile;
}
add_action('pxmi_saved_post', 'set_parent_id', 10, 1);
add_action('pmxi_update_post_meta', 'set_parent_id', 10, 1);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment