Flush rewrite rules on option update with Settings API

I register custom post type on init action and the validate which I’m writing about is set to register_setting inside admin_init action. This is the key to your issue. You’re registering the custom post type, and presumably you’re setting up the rewrite rules in that registration. When you call flush_rewrite_rules(), the rules are rebuilt right … Read more

Adding a rewrite rule to page that has no fixed variables and pagination

Got it to work, changing the regex from (.+) to (.*) Maybe helpful for others searching same rewrite on search and pagination. add_rewrite_rule(‘discover/interiors/interior-results/(.*)/page/([0-9]{1,})/?’, ‘index.php?pagename=discover/interiors/interior-results&tag1=$matches[1]&paged=$matches[2]’, ‘top’ ); add_rewrite_rule(‘discover/interiors/interior-results/(.*)’, ‘index.php?pagename=discover/interiors/interior-results&tag1=$matches[1]’, ‘top’ );

How to get default permalink link text?

When you are editing a post you can notice the URL in your browser looks like http://***.com/wp-admin/post.php?post=1351&action=edit The number in the URL corresponds to the ID of your post. So you can access your post with that ID. In this example the short link for the post would be http://***.com/?p=1351 When a visitor browsers this … Read more

How to change custom post type slug

You can use register_post_type_args to modify slug of any custom post type. You need to change portfolio slug to work? Then code should be like this. add_filter( ‘register_post_type_args’, ‘change_slug_portfolio_to_work’, 10, 2 ); function change_slug_portfolio_to_work( $args, $post_type ) { if ( $post_type == ‘portfolio’) { $args[‘rewrite’][‘slug’] = ‘work’; } return $args; }

Custom rewrite after the default term link URL

(Revised answer) So Let’s See The Issues With Your Rewrite Rule.. The first parameter passed to add_rewrite_rule() (which is the regular expression pattern) should not start with home_url() or any functions which outputs the website URL. So this is wrong: home_url() . ‘/car/([^/]*)/([^/]*)/?’ because the generated regular expression (RegEx) pattern would be: http://example.com/car/([^/]*)/([^/]*)/? which will … Read more

Custom post type archive with page as parent url

Yes. First, unregister the post type. (None of the actual data will be deleted if you already have posts.) Then, re-register it with ‘rewrite’ => array(‘slug’ => ‘page-name/custom-post-type-archive’) This will set your archive at the URL you’re looking for, and all the individual CPT posts will be “under” that – i.e. ‘/page-name/custom-post-type-archive/single-title/’.

How to add custom rewrite rules and point to specific templates

You need to create query_var for sector and you need to create a rewrite rule with RegEX. I created a plugin for this. Create a file and add into the wp-content/plugins folder and activate it. <?php /* Plugin Name: Custom Rewrite Plugin URI: https://serkanalgur.com.tr Description: Custom Rewrite Version: 1 Author: Serkan Algur Author URI: https://www.serkanalgur.com.tr … Read more