Skip to content

Instantly share code, notes, and snippets.

@RickeyMessick
Created October 1, 2014 16:25
Show Gist options
  • Save RickeyMessick/b1524600ff1ae54d60b1 to your computer and use it in GitHub Desktop.
Save RickeyMessick/b1524600ff1ae54d60b1 to your computer and use it in GitHub Desktop.
wp import all - pmxi_saved_post setting parent page from tax
add_action('pmxi_saved_post', 'wp_import_set_parent_locations', 10, 1);
function wp_import_set_parent_locations( $post_id ){
$terms = get_the_terms($post_id , 'states');
//$post_parent_id = get_page_by_title( $terms );
if ( !empty( $terms ) ) {
foreach ( $terms as $term ) {
$post_parent_id = get_page_by_title( $term->name, 'OBJECT', 'locations');
}
}
$my_post = array(
'ID' => $post_id,
'post_parent' => $post_parent_id->ID
);
// update the post, which calls save_post again
wp_update_post( $my_post );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment