remove sub-category of Custom Post Type from permalink structure
Here is what I ended up with. Needs some clean up on my end still but it works. https://gist.github.com/curtismchale/fa8d0570ce2c9b14880f31766c560872
Here is what I ended up with. Needs some clean up on my end still but it works. https://gist.github.com/curtismchale/fa8d0570ce2c9b14880f31766c560872
1. Change new_category taxonomy’s rewrite rule while registering: ‘rewrite’ => [‘hierarchical’ => false, ‘with_front’ => false, ‘slug’ => ‘news’] Make sure rewrite rule of news post type is default or: ‘rewrite’ => [‘slug’ => false, ‘with_front’ => false] 2. Add rewrite rules for new_category: add_action(‘init’, function() { add_rewrite_rule(‘^news/([^/]+)/?$’, ‘index.php?new_category=$matches[1]&post_type=news’, ‘top’); }); 3. Filter news post … Read more
add_rewrite_rule() cannot automatically create that permalink structure for you. You should use wp_link_pages_link filter. E.g: add_filter(‘wp_link_pages_link’, function($link, $i) { global $post, $photo_id; if ($photo_id && ‘gallery’ === $post->post_type) $link = $link . “https://wordpress.stackexchange.com/” . intval($photo_id) . “https://wordpress.stackexchange.com/”; return $link; }, PHP_INT_MAX, 2); Then, you must use add_rewrite_tag() to make WordPress aware of photo query string: … Read more
The custom rule you are trying doesn’t meet the criteria. Here’s a nifty online .htaccess tester tool to see to check rewrite logic. Use the follow RewriteRule instead: RewriteCond %{QUERY_STRING} (^|&)name=(.*) RewriteRule ^(.*)$ /profile/%2/? [R=301,L] Be sure to replace ^example\.com$ on the first line with your actual domain. You can also embed it in the … Read more
Thats posible by using Custom Structure of the permalinks like below: /%category%/%year%/%monthnum%/%postname%/ You will also be able to get a monthly archive of the category by going to: /%category%/%year%/%monthnum%/ like: www.yoursite.com/my-blog/2016/09/
Ok after 4 hours I managed to make it work function pl_add_rewrite_rule() { // this works with pagination too add_rewrite_rule(‘^slike(\/([a-z]+))?(\/([a-z]+))?(\/page\/([0-9]+))?$’,’index.php?page_id=45893&carstvo=$matches[2]&kategorija=$matches[4]&paged=$matches[6]’,’top’); add_rewrite_tag(‘%carstvo%’,'([^/]*)’); add_rewrite_tag(‘%kategorija%’,'([^/]*)’); } add_action(‘init’, ‘pl_add_rewrite_rule’, 10, 0);
Answered thanks to Milo’s comment. I wrote a small function to check if the query variable exists. Note that get_query_var(‘listen’) didn’t work for me. function is_listen() { $vars = $GLOBALS[‘wp_query’]->query_vars; if ( array_key_exists(‘listen’, $vars) ) { return true; } else { return false; } } Use it in a conditional like so: if ( is_listen() … Read more
in the args try to add this : “rewrite” => FALSE,
Thanks Nick! I thought that would work, and I placed it right after “RewriteEngine On” so it came first. I did find a working solution for handling it though (after 2 hrs): RewriteRule ^page/(.*)$ /$1 [G] In case anyone else needs to do the same …
Depending on how you are registering your custom post types, you can simply set the rewrite rules for it like so: $args = array( ‘description’ => ‘Photograph Post Type’, ‘label’ => __(‘Photographs’), ‘public’ => true, ‘rewrite’ => array( ‘slug’ => ‘photograph’), ); register_post_type( ‘photograph’ , $args ); If (for some bizarre reason) you don’t have … Read more