Id like to have user submitted content for some of my custom post types. I would like the system to check and provide a “did you mean” suggestion box to prevent suggestions of already present posts. And then check against a blacklist of terms to prevent submission. If both check, then the post can be submitted for review.
I was going to try doing this with formidable forms, but it doesnt seem to have a post search function, and I’m not sure if it would submit to my metabox created tables.
In laravel, the code is something like this, But not sure how to implement that within WordPress:
public function hobbyExists($value)
{ $hobbies = Hobby::where(‘hobby_name’, ‘like’, ‘%’.$value.’%’)
->where(‘status’, ‘!=’, 2)
->get([‘hobby_name’, ‘slug’]);
$names = HobbyAltName::with(‘hobby’)
->where(‘name’, ‘like’, ‘%’.$value.’%’) //
->where(‘is_approved’, 1)
->get([‘name’, ‘id’, ‘hobby_id’]);
if ($hobbies->count()) {
$this->hobbies = $hobbies; } else { $this->hobbies = []; }
if ($names->count()) {
$this->altnames = $names; } else { $this->altnames = []; }
if ($names->count() || $hobbies->count()) {
return $this->message = ‘Your Suggestion may exist’; }
elseif ($this->isBlacklisted($value)) { return true; }
else { return $this->message = ”; } }
​
[ad_2]