advanced-query-loop icon indicating copy to clipboard operation
advanced-query-loop copied to clipboard

Add compare value type setting in meta_query

Open jasalt opened this issue 11 months ago • 1 comments

Adding value type comparison would allow filtering by post meta compared as type. Example WP_Query args using dates in post meta which I would like to achieve:

[
'post_type' => ['post', 'event'],
'meta_query' => [
	'relation' => 'AND',
	[
	'key' => 'show_in_bulletin_section,
	'value' => 'yes'
	],
  [
	'key' => 'show_in_bulletin_section_until',
	'value' => date('Y-m-d', strtotime('-1 day')), // includes today in results
	//'value' => date('Y-m-d'), // today would not be included
	'compare' => '>',
	'type' => 'DATETIME'  // <- This is not possible with the plugin AFAIK
  ]
],
]

Wondering how well this could be achieved while avoiding to allow user inject PHP via value fields. Maybe some preset values could be used as in https://github.com/ryanwelcher/advanced-query-loop/issues/54.

jasalt avatar Jan 05 '25 14:01 jasalt

Thanks for submitting this! It's already being tracked in #4 but I'll close it in favor of this.

For my reference: https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

ryanwelcher avatar Mar 13 '25 20:03 ryanwelcher