Preserving $_GET parameter while using custom Rewrite Rule
There is an API for exactly your use case: endpoints. Register an endpoint for EP_PERMALINK and when it is set display your form.
There is an API for exactly your use case: endpoints. Register an endpoint for EP_PERMALINK and when it is set display your form.
Does this work for you? Seems to work when I try it. function qd_settings_api_init() { add_settings_section( ‘qd_theme_setting_section’, ‘Theme Reading Settings’, ‘qd_theme_setting_section_callback_function’, ‘reading’ ); add_settings_field( ‘qd_news_page’, ‘News Page’, ‘qd_news_page_dropdown_cbf’, ‘reading’, ‘qd_theme_setting_section’ ); if (delete_transient(‘qd_flush_rules’)) flush_rewrite_rules(); // * Added register_setting( ‘reading’, ‘qd_news_page’, ‘qd_sanitize’ ); // * Changed } /* Added this function. */ function qd_sanitize($input) { set_transient(‘qd_flush_rules’); … Read more
ok, so I thought I’d come back and answer my own question in case its useful to someone else. To start, the CPT: ‘query_var’ => true, ‘has_archive’ => false, ‘rewrite’ => array( ‘slug’ => ‘resources’, ‘with_front’ => false ), Tax1: ‘query_vars’ => true, ‘rewrite’ => array( ‘slug’ => ‘resources/type’, ‘with_front’ => false ) Tax2: ‘query_vars’ … Read more
This seems to work! ?post_type=directors&name=$matches[1] seems to be the key add_rewrite_rule( ‘directors/([^/]*)/showreels/([^/]*)/video/([^/]*)/?’, ‘index.php?post_type=directors&name=$matches[1]&showreel=$matches[2]&video=$matches[3]’, ‘top’ ); so final code now; function wpse13483_init() { add_rewrite_rule( ‘directors/([^/]*)/showreels/([^/]*)/video/([^/]*)/?’, ‘index.php?post_type=directors&name=$matches[1]&showreel=$matches[2]&video=$matches[3]’, ‘top’ ); } add_action( ‘init’, ‘wpse13483_init’ ); function wpa52794_query_vars( $vars) { $vars[] = ‘video’; $vars[] = ‘showreel’; return $vars; } add_filter( ‘query_vars’, ‘wpa52794_query_vars’ );
Was able to get this working. Thought I would write down what we did in the hopes that it will help someone in the future (or someone can give me feedback on how to better improve it!) Registered Custom Rewrite Rules add_action(‘init’, ‘pub_rewrite_rules’); function pub_rewrite_rules() { global $wp_rewrite; $wp_rewrite->add_rewrite_tag( ‘%pubyear%’, ‘([0-9]{4})’, ‘pubyear=”); $wp_rewrite->add_rewrite_tag( “%pubmonth%’, ‘([0-9]{2})’, … Read more
This is untested, but should work for you. Visit the permalinks settings page to flush rewrite rules after adding: function wpa_fix_blog_pagination(){ add_rewrite_rule( ‘blog/page/([0-9]+)/?$’, ‘index.php?pagename=blog&paged=$matches[1]’, ‘top’ ); } add_action( ‘init’, ‘wpa_fix_blog_pagination’ );
You can use the function get_query_var(). Like so: $event_slug = get_query_var(‘event_slug’); More info in the Codex.
I’m not sure it’s possible, or perhaps it just may not be the best approach. Here is my reasoning: domain.com/post-type-name/taxonomy-name/term-name/post-title/ Posts can be attached to multiple terms, so in essence there could be multiple links to the same post: domain.com/post-type-name/taxonomy-name/term-name/post-title/ domain.com/post-type-name/taxonomy-name/term2-name/post-title/ domain.com/post-type-name/taxonomy2-name/term3-name/post-title/ domain.com/post-type-name/post-title/ Depending on how you got there. You will definitely be able to … Read more
Create an endpoint. In the callback function for the endpoint call your plugin functions internally, so the whole WordPress environment is available and you are still on the same domain, no matter where the plugin URL is. Plus, make sure not to flush the rewrite rules on every page load, use the (de)activation hook for … Read more
adding these functions should do the trick. First things first, add this line to functions.php while you are working on this: add_action(‘init’, ‘flush_rewrite_rules’); What that code will do is constantly flush the rewrite rules, it makes this easier to test while you are working on it, instead of having to go in and manually reset … Read more