Last active
October 7, 2021 14:01
-
-
Save itsHall/0af538fa927765c957ebc91437b61e31 to your computer and use it in GitHub Desktop.
Set Page Parents of CPT | WP
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
<?php | |
// Set page parents of Custom Post Types - in the Organisation Setting ACF Options page | |
// Based upon Joe Sexton's blog post http://www.webtipblog.com/setting-wordpress-custom-post-type-parent-specific-page/ | |
function mpc_cpt_parent_page( $data, $postarr ) { | |
global $post; | |
// Verify if this is an auto save routine. | |
// If it is, our form has not been submitted - so we don't want to do anything | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { | |
return $data; | |
} | |
if ( $post->post_type == "my-custom-post-type" ){ | |
$data['post_parent'] = 1337; | |
} | |
return $data; | |
} | |
add_action( 'wp_insert_post_data', 'mpc_cpt_parent_page', '99', 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment