I using REGEXP in wp_query. I am storing post meta as 20181020 (yyyymmdd) so basically I want a REGEXP so that I can filter if user enter 10 (mm) in filter box
currently I am using this '^'.$date
but this only works if user entered yyyymm format. I want to search this if use enter value in either yyyy or mm there is no need for dd.
I want to filter based on user input.
User will select month or year, for example, if user select Dec month then i will get response 10. Then i pass this value in meta_query. here is the meta query. But in this issue is data stored in post meta is in yyyymmdd format. So I want a regexp where I can query to 4th occurrence.
$args = array(
'post_type' => 'achievements',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'achievement_date',
'value' => '^'.$date,
'compare' => 'REGEXP'
)
)
);
$the_query = new WP_Query( $args );
I figured it out. i just need to use this ^....
expression. This will skip first 4 characters.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.