Created
October 11, 2016 13:38
-
-
Save leobaiano/aef02b1ed30f2ab132e7d664435f89b1 to your computer and use it in GitHub Desktop.
[WordPress] - It allows you to use CPT and pages relative
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('parse_request', 'cpt_parent_page' ); | |
function cpt_parent_page( $wp ) { | |
if ( isset ( $wp->query_vars['attachment'] ) && ! empty( $wp->query_vars['attachment'] ) ) { | |
$page = get_page_by_path( | |
$wp->request, | |
OBJECT, | |
array( 'page', 'book' ) | |
); | |
if ( $page instanceof WP_Post ) { | |
$wp->query_vars = [ 'page_id' => $page->ID ]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment