Custom Post Type rewrite url to /category/pagetitle [duplicate]
As said in the comments by Milo (many thanks!) the answer was already posted: Permalinks: custom post type -> custom taxonomy -> post
As said in the comments by Milo (many thanks!) the answer was already posted: Permalinks: custom post type -> custom taxonomy -> post
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
With the Basic WP .htaccess rules it should at least be taking you to /site and /anothersite on the WordPress install and driving a 404. However it appears your server is handling 404 errors without passing them to WordPress. You may be able to add a custom php5.ini file with the directive cgi.fix_pathinfo = 1. … Read more
Don’t touch the .htaccess file, there’s this neat tool add_rewrite_rule() which you should hook into init: add_action(‘init’, function() { add_rewrite_rule( ‘search+([^/]+).html$’, ‘index.php?my_custom_search=1&s=$matches[1]&submit=Search’, ‘top’ ); }); Right after that you should flush the rewrite rules once ( by saving the permalink settings in Settings > Permalinks or with flush_rewrite_rules() BUT call that function only once and … Read more
I’ve actually had a brain fart, and just figured it out.. Since I don’t have any single posts, there was no reason to even be rewriting the CPT itself. I simply removed the rewrite line from the CPT and everything is working perfectly.
It works for me. add_filter(‘post_link’, ‘locale_permalink’, 10, 3); add_filter(‘post_type_link’, ‘locale_permalink’, 10, 3); function locale_permalink($permalink, $post_id, $leavename) { if (strpos($permalink, ‘%category_slider%’) === FALSE) return $permalink; $post = get_post($post_id); if (!$post) return $permalink; if ($post->post_type != ‘post’) { return $permalink; } else { $terms = wp_get_object_terms($post->ID, ‘category_slider’); if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug; else … Read more
I think the add_rewrite_rule is the correct route to go and I think what you have is correct also barring the Regex. Try substituting what you have currently for this => ^my-page\/([0-9]+)\/?. Full code below: function setup_filter_rewrites(){ add_rewrite_rule(‘^my-page\/([0-9]+)\/?’, ‘index.php?pagename=my-page&my_var=$matches[1]’, ‘top’); } add_action( ‘init’, ‘setup_filter_rewrites’ );
function custom_rewrite_rules() { add_rewrite_rule( ‘^art-classes/([^/]*)/([^/]*)/?$’, ‘index.php?product_cat=$matches[1]&location=$matches[2]’, ‘top’ ); } add_action(‘init’, ‘custom_rewrite_rules’); The $ at the end did the job. Not sure why.
If you are using this in a plugin, from the codex: To get permalinks to work when you activate the plugin use the following example, paying attention to how my_cpt_init is called in the register_activation_hook callback: add_action( ‘init’, ‘my_cpt_init’ ); function my_cpt_init() { register_post_type( … ); } function my_rewrite_flush() { // First, we “add” the … Read more
Associate custom CPT with another CPT’s taxonomy and rewrite permalinks