Filtering WP_Query based on wp_postmeta keys values

In the context of a WordPress widget development, I use WP_Query this way:

$args = array(
‘post_type’ => ‘myType’,
‘post_per_page’ => $number,
‘showposts’ => $number
$latest_myTypes = new WP_Query($args);
if ($latest_myTypes->have_posts()):
global $post; //etc.

When a myType post is saved, it stores some values in the table wp_postmeta, in particular two keys: day (an integer) and month (a string).

As you can see, in the preceding code I get all the posts of type myType.

I need a different thing: since any single post contains upcoming events, I want to get all the posts where the date is equal or after the current date (so, day must be at least today AND the month should be at least the current month).

Is it possible to modify my WP_Query to filter the posts this way?

I’ve red about meta_query but I’ve not understood how to integrate a meta query to my current query, and even how to create the query itself.

In pseudocode, I should get all the posts WHERE:

day >= date(“j”)


date(“n”, strtotime(month)) >= date(“n”)

Can you help me?

Read more here:: Filtering WP_Query based on wp_postmeta keys values

Leave a Reply

Your email address will not be published. Required fields are marked *