Skip to content

Instantly share code, notes, and snippets.

@aishahenderson
Created June 7, 2018 20:23
Show Gist options
  • Select an option

  • Save aishahenderson/dd31f83ff4559221bd5a351d2975a69c to your computer and use it in GitHub Desktop.

Select an option

Save aishahenderson/dd31f83ff4559221bd5a351d2975a69c to your computer and use it in GitHub Desktop.
WordPress Update and Save Post Dynamically
<?php
add_action( 'save_post', 'modify_post_content' );
function modify_post_content( ) {
$postArgs= array(
'post_type' => 'prime_activities',
'post_parent' => 0,
'date_query' => array(
array(
'after' => 'April 2nd, 2018',
'inclusive' => true,
),
),
'post_status' => 'publish',
'posts_per_page' => -1
);
$postReq= new WP_Query($postArgs);
foreach ( $postReq->posts as $my_post ) {
$post = array(
'ID' => $my_post->ID,
'comment_status' => 'open'
);
remove_action( 'save_post', 'modify_post_content' );
wp_update_post( $post );
add_action( 'save_post', 'modify_post_content' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment