• I am trying to find a way to auto-generate the begning of post title with numbers order
    for exemple :

    Category 1 :
    post one title : 001 [ my own title ]
    post two title : 002 [ my own title ]
    post three title : 003 [ my own title ]
    etc

    and

    category 2 :

    post one title : 500 [ my own title ]
    post two title : 501 [ my own title ]
    post three title : 502 [ my own title ]
    etc

    if not possible titles I can accept TAG GENERATOR

    • This topic was modified 3 years, 4 months ago by Jan Dembowski.
Viewing 1 replies (of 1 total)
  • You can force the title and post name (slug) be whatever you like (that’s not already taken) through the ‘wp_insert_post_data’ filter. This would not be reflected on the editor screen though until the page reloads. To get the editor screen to default to the right title from the start will probably require JavaScript of some sort. The specifics depend on the editor being used. Even with an editor default, you’ll still need the ‘wp_insert_post_data’ enforcement so users cannot alter the title through the editor or through more nefarious means. You could use JS to make the title field read-only, but you still would want the ‘wp_insert_post_data’ enforcement in case someone is more nefarious in their efforts.

    You’ll need to store the next available number as an option value and auto-increment it every time a new post is created. Doing so from the ‘wp_insert_post_data’ callback will work, but post insertion isn’t guaranteed at this point, so there could be gaps in the numbering if incrementing succeeds but post insertion does not. If sequential numbering is required, use a hook that fires after successful insertion, like “save_post_{$post->post_type}”.

    Be sure you only set the title and increment the number for new posts, not for updates.

Viewing 1 replies (of 1 total)
  • The topic ‘Generate PREFIX numbers for posts’ is closed to new replies.