Skip to content

Instantly share code, notes, and snippets.

@ashleyfae
Created March 24, 2016 13:54
Show Gist options
  • Save ashleyfae/770c0d0f8879571424ed to your computer and use it in GitHub Desktop.
Save ashleyfae/770c0d0f8879571424ed to your computer and use it in GitHub Desktop.
Example WP_Query for posts in a CPT published this month.
<?php
/**
* Example WP_Query for posts in a CPT published this month.
* @link http://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters
*/
// Get today's date. We use this to get the current month/year.
$today = getdate();
// Set up our arguments for the WP_Query.
$args = array(
'post_type' => 'release', // Set this to your CPT key
'post_status' => array( 'publish', 'future' ), // Pull out published posts or scheduled ones (no drafts/private)
'date_query' => array(
array(
'year' => $today['year'],
'month' => $today['mon']
)
)
);
// Now create the query.
$releases_query = new WP_Query( $args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment