Created
February 28, 2016 23:25
-
-
Save brichards/eb63ef260ceba3cf575a to your computer and use it in GitHub Desktop.
In all of the below cases permalinks have been flushed. The endpoint works perfectly fine for all scenarios _except_ the home page.
This file contains hidden or 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
Using only this, hiting ^/bpa/whatever/ serves blog archive instead of static front page. | |
<?php | |
/** | |
* Create url endpoint for BPA | |
* | |
* @since 1.0.0 | |
*/ | |
function cfpurl_rewrite_rules() { | |
add_rewrite_tag( '%bpa%', '([^&]+)' ); | |
add_rewrite_endpoint( 'bpa', EP_ALL ); | |
} | |
add_action( 'init', 'cfpurl_rewrite_rules' ); |
This file contains hidden or 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
Using only this, hitting ^/bpa/whatever/ redirects to ^/ | |
<?php | |
/** | |
* Create url endpoint for BPA | |
* | |
* @since 1.0.0 | |
*/ | |
function cfpurl_rewrite_rules() { | |
add_rewrite_tag( '%bpa%', '([^&]+)' ); | |
add_rewrite_endpoint( 'bpa', EP_ALL ); | |
$homepage = get_option( 'page_on_front' ); | |
add_rewrite_rule( '^bpa(/(.*))?/?', 'index.php?p=' . $homepage . '&bpa=$matches[2]', 'top' ); | |
} |
This file contains hidden or 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
Using only this, hitting ^/bpa/whatever/ redirects to ^/ | |
<?php | |
/** | |
* Create url endpoint for BPA | |
* | |
* @since 1.0.0 | |
*/ | |
function cfpurl_rewrite_rules() { | |
add_rewrite_tag( '%bpa%', '([^&]+)' ); | |
add_rewrite_endpoint( 'bpa', EP_ALL ); | |
} | |
add_action( 'init', 'cfpurl_rewrite_rules' ); | |
function cfpurl_home_query_update() { | |
if ( is_admin() ) { | |
return; | |
} | |
global $wp_query, $wp_the_query; | |
remove_action( 'parse_query', 'cfpurl_home_query_update', 11 ); | |
// If we have a homepage and should be showing it, we have to | |
// completely reset the query and make sure it's handles as | |
// the "main" query, for it to recognize this properly without | |
// a redirect. | |
if ( 0 === strpos( $_SERVER['REQUEST_URI'], '/bpa/' ) ) { | |
$homepage = get_option( 'page_on_front' ); | |
if ( $homepage ) { | |
$wp_query = $wp_the_query = new WP_Query( array( | |
'bpa' => get_query_var( 'bpa' ), | |
'page_id' => $homepage, | |
) ); | |
} | |
} | |
} | |
add_action( 'parse_query', 'cfpurl_home_query_update', 11 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you know anything about if this was fixed? I still have this problem...