Skip to content

Instantly share code, notes, and snippets.

@itsHall
Last active October 7, 2021 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsHall/0af538fa927765c957ebc91437b61e31 to your computer and use it in GitHub Desktop.
Save itsHall/0af538fa927765c957ebc91437b61e31 to your computer and use it in GitHub Desktop.
Set Page Parents of CPT | WP
<?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