35664

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..

Answer1:

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.

Answer2:

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.

Answer3:

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!

Recommend

  • add_row in ACF Pro isn't saving repeater values
  • wordpress update_post_meta and get_post_meta
  • How to migrate from Yii to Woocommerce Wp, Still keep to old database (table,rows) [closed]
  • Chef: Force use of modified attributes in template
  • Replacing NULL value in current row based on 'closest' matching 'earlier' row. (
  • How to prevent certain internal routes from being accessed by the user?
  • PostgreSQL: update with left outer self join ignored
  • NoReverseMatch at / Reverse error with urlresolvers, get_absolute_url()
  • Why won't this override of the Model.save() function in Django work?
  • LibGit2Sharp log remote
  • Mongodb $addToSet of nested object
  • Can I plot times when they're given as UNIX timestamps with added milliseconds?
  • How to add an object in my collection by only using add method? [closed]
  • Jackson Java 8 DateTime serialisation
  • How can I select the most recent and distinct records using LINQ?
  • Create registry key in 32-bit hive on x64 PC using Installshield 2012 LE - Avoid redirection
  • RavenDB indexing errors
  • Using Nested Table variables / Collections in SQL inside PL/SQL blocks
  • Eloquent update method change created_at timestamp
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • Illegal mix of collations for operation for date/time comparison
  • R: gsub and capture
  • Calling of Constructors in a Java
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Traverse Array and Display in markup
  • Transpose CSV data with awk (pivot transformation)
  • Comma separated Values
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Free memory of cv::Mat loaded using FileStorage API
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Memory offsets in inline assembly
  • embed rChart in Markdown
  • Turn off referential integrity in Derby? is it possible?
  • How can I remove ASP.NET Designer.cs files?
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • How can I use threading to 'tick' a timer to be accessed by other threads?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?