Created
March 24, 2016 13:54
-
-
Save ashleyfae/770c0d0f8879571424ed to your computer and use it in GitHub Desktop.
Example WP_Query for posts in a CPT published this month.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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