Created
June 7, 2018 20:23
-
-
Save aishahenderson/dd31f83ff4559221bd5a351d2975a69c to your computer and use it in GitHub Desktop.
WordPress Update and Save Post Dynamically
This file contains hidden or 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 | |
| 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