• I’m having some trouble on a plugin I’m writing. I need the post_name to match what I tell it, but it keeps replacing consecutive dashes with a single dash. So I use:

    ‘post_name’ => ‘wegokuhn–jg4ew-g4’

    but by the time it gets to the database it’s ‘wegokuhn-jg4ew-g4’

    This is stopping me from effectively identifying duplicate posts. Is there any way to stop this particular action from happening when using wp_insert_post?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    This will remove the filter that strips double dashes:
    remove_filter('sanitize_title', 'sanitize_title_with_dashes', 10, 3 );

    However, that function does some other important sanitization besides strip double dashes. You really should replace sanitize_title_with_dashes() with a custom version that does everything except strip double dashes.

    Additionally, if pretty permalinks are being used, double dashes in post slugs will cause such requests to 404, so any plugin that allows double dashes will not be usable by most people.

    Thread Starter DuncanClarke

    (@duncanclarke)

    Thanks for that. I didn’t realise that anything else relied on it. Though my plugin is only for my own site I do want to keep it as portable as possible.

    I’ll drop the search on post_name and instead do a slightly less conclusive search on post_title and tags_input. Every post made to the site is automatic so these should be identical each time. Just not quite the guarantee of uniqueness but enough to mitigate the risk.

    Your help has been much appreciated and saved me a lot of time chasing my tail.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘post_name and —’ is closed to new replies.