url rewriting for custom post types

Yes you can use the rewrite parameter when creating your custom post type: register_post_type( ‘example_type’, array( ‘labels’ => array( ‘name’ => “Example-Type”, ‘singular_name’ => “example-type” ), ‘public’ => true, ‘has_archive’ => true, ‘rewrite’ => array(‘slug’ => ‘the-url-you-want’, ) ); } You will need to reset your permalinks for it to take effect as well. EDIT: … Read more

URL Rewrite – Page Archive

You need to add following two functions in theme functions.php or in a plugin’s php file function func_rewrites_init(){ add_rewrite_rule( ‘programme/(\d+)/(\d+)/?$’, ‘index.php?pagename=programme&pmonth=$matches[1]&pdate=$matches[2]’, ‘top’ ); } add_action(‘init’, ‘func_rewrites_init’); function func_query_vars( $query_vars ){ $query_vars[] = ‘pmonth’; $query_vars[] = ‘pdate’; return $query_vars; } add_filter( ‘query_vars’, ‘func_query_vars’ ); pagename value in the above code have to be according to template … Read more

Rewrite rule and display of post

I don’t understand why but the regex seemed to be the last issue. It was catching it but even with the post name hardcoded in it didn’t work correctly. This is the final working version. add_filter( ‘post_link’, ‘custom_permalink’, 10, 3 ); add_filter(‘rewrite_rules_array’,’wp_insertMyRewriteRules’); add_filter(‘init’,’flushRules’); function custom_permalink( $permalink, $post, $leavename ) { $category = get_the_category($post->ID); if ( … Read more

Create rewrite rule for subpage

I do something similar. I have a page (country_tc) that uses a custom page template that either dynamically generates info for requested country, or a series of sub-pages for the country e.g. /country/Egypt (index.php?pagename=country&countrytc=egypt) /country/egypt/safety (index.php?pagename=country&countrytc=egypt/safety) I use page_rewrite_rules for the re-write. I’ve not had time to vet your code, so this is how I’d … Read more