0

How do I create a custom meta box for posts which have a boolean data type and can be true only for one post. I want it to be falsified for all other posts when it's set on one post.

  1. Is there a hook that runs right after a custom field is saved in the create post screen?
  2. Is there a way to do this with the metabox plugin?
  3. For example if you want to create a featured post feature, only one post can be a featured post. Is there a way to create a single featured post without using custom meta boxes?
1
  • 1
    So you want to have something that says this is the post, not the other posts, this one? Post meta isn't what you want, that sounds like an option, perhaps you should look at settings and adding to a settings page, the same way you can choose a page to be the frontpage of your site
    – Tom J Nowell
    Commented Jul 25, 2016 at 15:46

1 Answer 1

2

Storing of your own meta fields is typically a custom process, more so if you are using a third party framework.

Technically it's possible, but clunky:

  1. Hooking into save_post would allow you to check if meta is added to it
  2. If so you can immediately query for previous (if any) post that had it and unset the meta for it

However I concur with the comment you got that this does not essentially seem to fit a purpose of post meta well. There are precedents in core itself (for example front/posts page handling) to store such things as post's ID in an option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.