Created
December 21, 2018 06:49
-
-
Save ruucm/59cce22ba4690839cdfc3e2547357c33 to your computer and use it in GitHub Desktop.
add specific term to last 2 month posts (wordpress)
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 | |
$args = array( | |
'post_type' => 'cartoon', | |
'post_status' => 'publish', | |
'orderby' => 'date', | |
'order' => 'DESC', | |
// Using the date_query to filter posts from last 2 month | |
'date_query' => array( | |
array( | |
'after' => '2 month ago' | |
) | |
), | |
'posts_per_page' => -1 | |
); | |
$query = new WP_Query( $args ); | |
$found_posts = $query->found_posts; | |
if ($found_posts > 0) { | |
$posts = $query->posts; | |
for ($i=0; $i < sizeof($posts); $i++) { | |
wp_add_object_terms( $posts[$i]->ID, 'new', 'new_or_popular' ); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment