CPT and rewrite rules

Finally, found a solution mix: The CPT has to have: ‘has_archive’ => ‘library’, // Fixes the archive URL. ‘rewrite’ => array( ‘slug’ => ‘library/%library-category%’, ‘with_front’ => false, ) Taxonomy should be as following: ‘rewrite’ => array( ‘slug’ => ‘library’, ‘with_front’ => false, ), And than you need to rewrite the links: /** * Custom rewrite … Read more

Custom Post Type Single Page and Archive Page redirects to Home Page

After hours of debugging I noticed that the problem was only reproduced when I used the library. Even if I used register_post_type, if I used any other functionality from the library before the register_post_type function call, it would cause some erratic behaviour. I opted on removing PostTypes from my project and simply sticking to register_post_type … Read more

Get WordPress username to customize url

You can only do that if the user is logged in (otherwise there is no “current” user). Depending on what your specific use case is, it would be something like this: if ( is_user_logged_in() ) { global $current_user; $current_user = wp_get_current_user(); // get the username: $username = $current_user->user_login; // set up the URL: $url = … Read more

Using a template file for a specific custom URL

I don’t know what nepal is (text prefix only or maybe taxonomy term), but it is not the most important thing, you will correct it if necessary. Rewrite rule like this should resolve the case. add_action( ‘init’, ‘se356109_events_custom_rule’ ); function se356109_events_custom_rule() { add_rewrite_rule( ‘nepal/events/(.+?)/([0-9\-]+)(:?/page/?([0-9]+))?/?$’, ‘index.php?events=$matches[1]&paged=$matches[3]’, ‘top’ ); } If you need to use URL date … Read more