I have a number of posts using the default post type. Each is assigned to a category and the permalink structure /category/postname. For one specific category I would like to use the permalink structure /someother/category/postname.

So for example category test_a and test_b all remain as standard but any post put in category test_c I would like the URL/permalink to be /someother/test_c/postname

Following what I have done similarly I have:

function my_category_post_link($permalink, $post, $leavename){

   if ($permalink == "https://example.com/test_c/post_1/"){
      return "https://example.com/someother/test_c/post_1/";
add_filter('post_link', 'my_category_post_link',10,3);

This is a highly simplified view and obviously I alter the logic, etc. Anyway I can get that bit to work. The resulting link results in a 404. Previously I would then add a add_rewrite_rule but this doesn't seem to work and to be honest not 100% it is the right thing to do. Can anyone just point me in the right direction?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.