Unable to Display Date Field in the Admin Filters Properly
I have created a date field admin filter, but the data isn’t displayed right. How to show the correct date in the admin filters?
While adding a date timestamp field in the Admin Filter, you cannot get what you expect. Instead of the date added to the post, you will get another result.
Firstly, let’s check what values should be represented during the Admin Filter creation.
Fill in the fields and mind to select the needed meta field. Update the post type once done.
Now the created options in the data filter will not look as you have typed them in. To fix this problem, use the PHP code.
Head to Appearance > Theme Editor. Open the functions.php tab and scroll down till the end of the code. Paste the required PHP code.
NOTE. Paste the Meta Field Key related to the meta field you have used while creating the Admin Filter.
For instance, we have created the Admin Filter based on the Date Timestamp meta field.
We have put the following meta field key during the meta field adding.
The final result will look like in the picture below. Put the Meta Field Key into the highlighted segment instead of the ‘__date’ example.
Once done, click on the “Update File” button. Head to the CPT where the Date Admin Filter is added.
Open the filter and check if everything works fine.
Now you know how to display the correct date options in the admin select filter.