Make Permalinks have a custom format?

Please see below. This will solve your problem for all future posts that you publish. I have tried this code. But to be on safer side, please backup your DB before you try or tray on staging. function custom_unique_post_slug( $slug, $post_ID, $post_status, $post_type ) { $post = get_post($post_ID); /* Set a flag to know if … Read more

WordPress custom post type rewrite rule matches all pages returning 404

I managed to find a solution thanks to Milo‘s previous answers on other related questions. I found this particular post Remove base slug in CPT & CT, use CT in permalink to be extremely helpful. My initial CPT with grandparent relationship rewrite remains the same: function cpt_child(){ $args = array( //code ‘rewrite’ => array( ‘slug’ … Read more

Custom post URLs

You can try the slug agument under rewrite parameter of register_post_type() function: add_action( ‘init’, ‘egister_hosts_post_type’ ); function register_hosts_post_type() { $args = array( // …. ‘rewrite’ => array( ‘slug’ => ‘programs/hosts’ ), ); register_post_type( ‘hosts’, $args ); } As this affect the rewrite rules, you should flush them on activation/deactivation of the plugin: add_action( ‘init’, ‘cyb_register_hosts_post_type’ … Read more

WP Job Manager Custom Permalink Returns 404 Errors

I had the same issue on my website http://loctim.com because I wanted the slug like this %category%/%state%/%city% I had 404 pages in changing functions.php and today it is the gallery which was crazy. So i worked all the night and I have found that I had forgotten this part of code : function add_category_endpoint_tag() { … Read more

how to use two permalinks for one custom post type based on categories

If anyone’s interested, the solution was quite close, I only had to specify the rewrite rule with &post_type=film : add_rewrite_rule( ‘projections_dvd/([^/]+)/?$’, ‘index.php?name=$matches[1]&post_type=film&is_projections_dvd=1’, ‘top’ ); I also changed the query vars to make it simpler : function wpd_query_var( $query_vars ) { $query_vars[] = ‘is_international’; $query_vars[] = ‘is_france’; $query_vars[] = ‘is_projections_dvd’; $query_vars[] = ‘categorie’; return $query_vars; } … Read more

Force/Limit the post/page slug to accept only url friendly characters

For now I used the sanitize_title filter, and removed all unwanted characters, which forces my users to use only [a-z0-9-] as a valid input for titles. ## Allow only [a-z0-9-] in the slug function my_clear_title($title) { $pattern = ‘/[^a-z_0-9- ]/i’; $replace_with=””; return preg_replace($pattern, $replace_with, $title); } add_filter(‘sanitize_title’, ‘my_clear_title’, 3, 1); I had to use a … Read more