I was talking to one of my cousins the other day about traveling to Spain, where she lives. I wanted to refer her to one of my blog posts about visiting Spain, when I realized I hadn’t posted it–for 19 years. Fortunately, I still had my written notes, so I quickly posted it. Then, I started wondering–if I wanted to browse all the posts I made in a certain year, in this case, 1999, I wouldn’t find it, because for one: the native WordPress search doesn’t search by metadata; and two, I had no field to search for the event date. So, even if I could search by metadata, a search for 1999 wouldn’t pick it up, because I posted in in 2018.
I had two problems, but I solved one of them pretty quickly by just adding a custom field with ACF (Advanced Custom Fields). Then, for my Spain post, I entered the date we left, ‘19990918.’
I solved the second problem with an outstanding function I found that adds a metadata search capability to the native WordPress search. And it works beautifully. But, oops, if I do a search for 1999, it returns the Spain post and all my posts made in 1999.
So, I needed a way to separate my new custom field from all the other post metadata. I solved that problem by entering a letter d at the beginning of the event date. For the Spain post, I entered d19990918, and now I can do a search on ‘d1999’ and pull up the Spain post and all events that took place in 1999.
Added bonus: now I can add the date of an event, instead of just putting the year in the title or content. It was just too anal to put the exact date of travel into the body of the content.