-
-
Save tommcfarlin/db581f4871687c7a11c514a47aa6f618 to your computer and use it in GitHub Desktop.
[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 | |
private function find_all_events( $event_id ) { | |
global $wpdb; | |
$events = $wpdb->get_results( | |
$wpdb->prepare(" | |
SELECT ID, post_content | |
FROM $wpdb->posts | |
WHERE post_parent = '%d' | |
AND post_status = 'publish' | |
", $event_id), | |
ARRAY_A | |
); | |
return $events; | |
} |
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 | |
public function update_future_events( $event_id ) { | |
$events = $this->find_all_events( $event_id ); | |
$iteration = 1; | |
foreach ( $events as $event ) { | |
preg_match_all( '/(\d+)/', $anniversary['post_content'], $matches ); | |
$original_year = $matches[0]; | |
$original_year = intval( $original_year[0] ); | |
$new_year = ( $original_year + $iteration ); | |
$iteration++; | |
// See forth-coming gist. | |
} | |
} |
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 | |
public function update_future_events( $event_id ) { | |
$events = $this->find_all_events( $event_id ); | |
$iteration = 1; | |
foreach ( $events as $event ) { | |
// See previous gist. | |
$event['post_content'] = str_ireplace( $original_year, $new_year, $event['post_content'] ); | |
wp_update_post(array( | |
'ID' => $event['ID'], | |
'post_content' => $event['post_content'], | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment