W
W
WordPress WooCommerce2015-12-11 12:37:09
WordPress
WordPress WooCommerce, 2015-12-11 12:37:09

Rewrite rule in WordPress. How right?

There is a cases post type
If nothing is done, the links look like cases/[name] where name is the WordPress post slug.
The goal is to make links like /cases/[id] where id is the post id
Before version 4.4, the following scheme worked:
1 https://github.com/systemo-biz/casepress/blob/mast...
2 https://github .com/systemo-biz/casepress/blob/mast...
But with WP 4.4. this scheme started to fail. When you try to comment, throws on a non-existent page.
If you comment out this logic, then the type path /cases/[name] is returned and the comments start working as expected.
I suspect that I did something wrong. Mb who will tell you the best way to make url rules for the scheme /[post_type]/[post_id]?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MetaDone, 2015-12-11
@MetaDone

add_filter('post_type_link', 'custom_post_link', 10, 2);
function custom_post_link($permalink, $post) {      
        if (('cases' == $post->post_type) && '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) {
            $permalink = "/cases/" . $post->ID . "/";
        }
        return $permalink;
}

Should work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question