Skip to content

Instantly share code, notes, and snippets.

@badlydrawnben
Created October 4, 2017 15:48
Show Gist options
  • Save badlydrawnben/a28d2b0d72b7b1878f2102ad41dae13f to your computer and use it in GitHub Desktop.
Save badlydrawnben/a28d2b0d72b7b1878f2102ad41dae13f to your computer and use it in GitHub Desktop.
ACF Options page - pick page parent of a CPT
// 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/
define( 'FRIENDS_PARENT_ID', get_field( 'friends_parent_page', 'option' ) );
add_action( 'wp_insert_post_data', 'biscuit_cpt_parent_page', '99', 2 );
function biscuit_cpt_parent_page( $data, $postarr ) {
global $post;
// if ( !wp_verify_nonce( $_POST['staff_parent_custom_box'], 'stc_cpt' ) )
// return $data;
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $data;
if ( $post->post_type == "friends" ){
$data['post_parent'] = FRIENDS_PARENT_ID ;
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment