I am trying to add a field to WordPress posts (not pages) which would simply include a label and a checkbox. Something like: Make this the sticky post? If check, the key should be set to TRUE or something that is easily accessible. The problem is, however, that I only want one post to have possibly the TRUE value. This means, when I have checked the field in post-1, and afterwards I check that field in post-2, post-1’s field value should be set to FALSE so that only one post can have TRUE at the same time.
I would then loop the post in my index.php to get the post that has value==TRUE and display it somewhere on the page. Something like this (not tested):
$args = array( 'order' => 'DESC', 'posts_per_page' => 1, 'meta_key' => 'post_sticky', ), ); $stickyPost = new WP_Query( $args );
Ideally I want this field to be set in my functions.php file, but from what I’ve gather on the Internet this isn’t as easy as it should be. You can add fields in WordPress itself, but I don’t want to do it like that because I am dependent on writers and I don’t want them fiddling around.
Read more here: Add field to posts (checkbox) that only one post can have