Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Template name: Update posts regex
- */
- // query for posts
- query_posts( array(
- 'post_type' = 'any', // get all post types
- 'posts_per_page' = -1, // all posts
- 'nopaging' = true // no pagination
- )
- );
- // loop
- if ( have_posts() ) : while ( have_posts() ) : the_post();
- // set vars
- $pattern = '/\[tab: .+? [0-9]\]/'; // regex pattern to match
- $replacement = '<!-- nextpage -->'; // replacement string
- $string = get_the_content(); // post content
- // match and replace
- $updated_content = preg_replace($pattern, $replacement, $string);
- // Set new post content
- $my_post = array();
- $my_post['ID'] = get_the_ID();
- $my_post['post_content'] = $updated_content;
- // Update the post into the database
- $result = wp_update_post( $my_post );
- endwhile; endif;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement