Millions
Millions

Reputation: 45

Purely numerical wordpress permalinks

Can I have single digit wordpress permalinks? Trying to force the permalink to "2" e.g. automatically rewrites it to "2-2".

Looking into it a bit further I discovered this is the case for any numerical permalink - I reckon it has to do with possible interference with paging but have a use case where I would like to use this structure..

Upvotes: 2

Views: 1411

Answers (3)

Bishal Sharma
Bishal Sharma

Reputation: 51

actually this can be easily done from the permalinks section in the settings. You can simply set /post_id/ as the permalink structure and it will work fine.

Upvotes: 1

moraleida
moraleida

Reputation: 424

I've dealt with this once by intercepting the post slug creation and "fixing" it somehow. Maybe you can work from this:

 /*
 * New permalink structure
 * 
 * Itercepts every wp_insert_post data to change the regular slugs to md5 hashes 
 * based on the Unix timestamp of action. This generates a new slug at every 
 * saving action, which protects the posts against unauthorised direct access.
 * 
 */
function rm_cpt_permalink_change($data) {

    if ($data['post_type'] == 'custom_post_type') {

                $time = time();
        $data['post_name'] = md5($time);
        return $data;
    } else {
            return $data;
        }
}
add_filter('wp_insert_post_data','rm_cpt_permalink_change',10,2);

Do you really need single-digit slugs? If you can have your way with 00001 or 000005, the wp_insert_post_data filter is probably the way to go.

Upvotes: 0

saibot
saibot

Reputation: 376

You probably already have a post with the slug '2'; if it's not in the post administration panel, it might still be in the trash.

On a side note, using digits as slugs might not be the best idea--it could conflict with paging and other rewrite rules, and might not describe what that post is for.

Hope this helps!

Upvotes: 0

Related Questions