Prevent Duplicate Post Titles with frm_new_post hook

By: Jamie VanRaalte | Asked: 09/29/2022
ForumsCategory: Code HelpPrevent Duplicate Post Titles with frm_new_post hook
Jamie VanRaalte asked 2 years ago

I have a form that creates posts set to pending for approval. However, posts are also created in the backend too so users who manage the site and users who visit the site can create the posts. I need a way to when the user enters their post title, for it to cross check against existing posts (NOT entries since not all posts have an entry) and then alert the user that a post already exists (this is for a directory type website). Formidable support directed me to a hook `frm_new_post/`

Has anyone done something like this already?

Bobby Clapp replied 2 years ago

That opens a can of worms. What will be done to check if the post exists? Is it by title only or some other set of data?

Jamie VanRaalte replied 2 years ago

In this case, only by title. I use a Duplicate Title Checker plugin on the backend so I just need the same functionality on the frontend.

Bobby Clapp replied 2 years ago

Seems like a query I'm not going to be able to write for you, but to help with others who may, should it be looking for exact word for word matches? Is this for SEO purposes?

Jamie VanRaalte replied 2 years ago

The Post Title will be a first and last name so generally an exact match will work but I could see how a user might enter a middle name or something too so while I'd be happy with an exact match, ideally something that catches some of the same words in the title would probably be best.

Thanks for looking and trying to help!

Bobby Clapp replied 2 years ago

As far as the post creation in formidable forms is concerned, if you are using separate first/last fields, you could add a new "read-only" field and combine those into that field and then set it to be "unique". That would help where you are at going forward, but not with anything that exists.

1 Answers
Victor Font answered 2 years ago

Considering all the variations there could be in a post title due to spelling or typing errors, you may want to consider a soundex search in addition to an exact match. Since this a front end request, this is how I would approach the requirement:

  1. Check the duplicate title plugin for hooks that you may be able to use on the front end
  2. If no plugin hooks, create a custom Ajax to monitor the title field and check for duplicates on the title field's blur event.

 
 

Jamie VanRaalte replied 2 years ago

Hi Victor, thanks for the tips! I appreciate that so much!

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right