add_rewrite_rule – Page Slug from “/foo-bar/” to “/foo/bar/”
This rule is what I ended up with after finding this post: Understanding add_rewrite_rule add_rewrite_rule( ‘^foo/([^/]*)/?$’, ‘index.php?pagename=foo-$matches[1]’, ‘top’ );
This rule is what I ended up with after finding this post: Understanding add_rewrite_rule add_rewrite_rule( ‘^foo/([^/]*)/?$’, ‘index.php?pagename=foo-$matches[1]’, ‘top’ );
flush_rewrite_rules is firing, but it’s too late; the previous rewrite setting has already determined your register_post_type args at the start of the request, so you’re just flushing the “old” rules. You could try re-registering the post type just before flushing, but I’m not sure of the wider implications or even if this will work. If … Read more
You’re almost there. You need to add the season and episode query vars to the array of recognized vars. Note the small change to your regex as well- function wpd_add_my_rule(){ add_rewrite_rule( ‘^([^/]+)/season-([0-9]+)/episode-([0-9]+)/?$’, ‘index.php?name=$matches[1]&season=$matches[2]&episode=$matches[3]’, ‘top’ ); } add_action( ‘init’, ‘wpd_add_my_rule’ ); function wpd_add_query_vars( $query_vars ) { $query_vars[] = ‘season’; $query_vars[] = ‘episode’; return $query_vars; } add_filter( … Read more
Two problems I see- rewrite rules need to set query vars that will result in a successful main query. Setting just a custom var like slide doesn’t parse to anything WordPress can load. Additionally, slide needs to be added to the recognized query vars for it to get parsed within a rule. So, what would … Read more
OK so after scratching my head for a day, I decided to rewrite the function. After searching for few minutes, I came across this tutorial that outlined the solution for me. It works like a charm. I hope it helps you guys too.
pagename assumes the page post type. You need to use the custom post type query var in your rule instead. Presumably you also want to detect that this is a request for en, you can add your own rewrite tag to store that, then add that to the rule: add_action(‘init’, ‘add_my_rule’); function add_my_rule() { add_rewrite_tag(‘%my_language%’, … Read more
It’s not clear from your question how important it is that the query string is action and the value test, but if all you need to do is have a /test URL, and be able to tell if it’s the /test URL so that you can process soemthing, then the simplest way is probably to … Read more
Replace all your above code with the one below: <?php function master_load_ads_txt_template_include( $template ) { $is_load_ads_txt = (bool) get_query_var( ‘ads-txt’ ); if ( $is_load_ads_txt ) { $template = locate_template( ‘template-parts/ads-txt.php’ ); } return $template; } add_filter( ‘template_include’, ‘master_load_ads_txt_template_include’ ); function master_load_ads_txt_rewrite() { add_rewrite_rule( ‘ads.txt’, ‘index.php?ads-txt=true’, ‘top’ ); // The line below doesn’t work and it’s … Read more
Without touching rewrites – you could probably do somthing like website.com/?goto-amazon=<?php echo get_the_ID() ?> Which’ed output website.com/?goto-amazon=42 Where 42 is an example of a post that contains the amazon_keywords. In your site you could listen for the goto-amazon query and redirect thereafter add_action( ‘init’, function(){ if (isset($_GET[‘goto-amazon’])) { $keywds = get_field(‘amazon_keywords’,intval($_GET[‘goto-amazon’])); $link = “http://www.amazon.co.uk/s/?_encoding=UTF8&camp=1634&creative=19450&field-keywords={$keywds}&linkCode=ur2&tag=AFFID”; wp_redirect($link); … Read more
They aren’t really connected. It’s just a redirect after all. The error means that some code in your website wrongly passes a WP_Error object to wp_kses_no_null(). In your position I’d put something like this into this function for debugging: if ( is_wp_error( $string ) ) { var_dump( $string ); debug_print_backtrace(); } This way you can … Read more