Created
October 1, 2014 16:25
-
-
Save RickeyMessick/b1524600ff1ae54d60b1 to your computer and use it in GitHub Desktop.
wp import all - pmxi_saved_post setting parent page from tax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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