I am trying to perform a query on a custom-type post using the value of a custom field.
This field contains a string date: dd.mm.yyyy.
The post type name is ‘event’
The custom field name is ‘date_event’
I would like to show all the EVENT that have the month of DATE_EVENT matching with the current month.
Any suggestion pls?
I did something similar, the technique you need to use is called a meta query.
Here is the query I wrote to get posts based on a date value stored as a custom field meta value.
'orderby' => 'meta_value_num'
will sort the results by the meta value'meta_key' => 'date_event'
tells what the custom field is calledmeta_query
is an array which specifies that the results must match both conditions, then we specify a minimum date and a maximum date.The date values must be stored either as
YYYY-MM-DD
or as a “Seconds since the Unix Epoch” value.