I am trying to rewrite urls in WordPress, but its not working

You can try add_action( ‘init’, ‘wpse26388_rewrites_init’, 10, 0); function wpse26388_rewrites_init(){ add_rewrite_rule( ‘^us-dot-numbers/([A-Za-z0-9-]+)/?’, ‘index.php?page_id=642&dotNumber=$matches[1]’, ‘top’ ); } add_filter( ‘query_vars’, ‘wpse26388_query_vars’ ); function wpse26388_query_vars( $query_vars ){ $query_vars[] = ‘dotNumber’; return $query_vars; } Remember to flush_rewrite_rules();

URL Rewrite and Archive Template Files – Post Type vs. Taxonomy

I handled this with a pre_get_posts hook (thanks, @Milo), passing in the URL part that corresponds to the slug I need. Hope this helps someone down the road. Improvements are welcome. Thanks. function filter_team_news_archives_by_sport_taxonomy($query) { if (is_post_type_archive(‘team-news’) && $query->is_main_query()){ // Get $sport_slug from URL — https://stackoverflow.com/a/36002190/4107296 $url = (isset($_SERVER[‘HTTPS’]) ? “https” : “http”) . “://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]”; … Read more

Broken page redirect

I found solution – I needed to run flush_rules() method at least once to clean cache. //Ensure the $wp_rewrite global is loaded global $wp_rewrite; //Call flush_rules() as a method of the $wp_rewrite object $wp_rewrite->flush_rules( false );

url rewriting on custom post type

I just realized i used different kind of rewriting which didn’t require @Jacob’s codes (using add_rewrite_endpoint) add_action(‘init’, ‘wpse42279_add_endpoints’); function wpse42279_add_endpoints() { add_rewrite_endpoint(‘play’, EP_PERMALINK); } And then i used this conditionals on the single page: global $post; $pid = $post->ID; $var = get_query_var( ‘play’ ); if( !empty($var) and $var == $pid) : // do stuff endif; … Read more