Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mag_check_for_new_issue_on_publish( $post_id ){
- // check that this is a real publish and not an update
- if( ( $_POST['post_status'] == 'publish' ) && ( $_POST['original_post_status'] != 'publish' ) ) {
- // is the post in the master category?
- if ( in_category( get_option( 'mag_master_category' ) , $post_id ) ) {
- // get the issue and assign this to global option current_issue
- $terms = get_the_terms ( $post_id , 'issue' );
- if ($terms) {
- update_option ( 'mag_current_issue' , $terms[0]->slug );
- }
- // publish all posts that are in the same issue
- $args = array(
- 'posts_per_page' => -1,
- 'post_status' => 'pending',
- 'tax_query' => array(
- array(
- 'taxonomy' => 'issue',
- 'field' => 'slug',
- 'terms' => $terms[0]->slug,
- )
- )
- );
- remove_action( 'publish_post' , 'mag_check_for_new_issue_on_publish' );
- // get list of posts
- $issue_pending_posts = get_posts( $args );
- // loop through and set each post_status to publish
- foreach( $issue_pending_posts as $pending_post ) {
- $pending_post->post_status = 'publish';
- wp_update_post( $pending_post );
- }
- add_action( 'publish_post' , 'mag_check_for_new_issue_on_publish' );
- }
- }
- }
- // register the action
- add_action( 'publish_post' , 'mag_check_for_new_issue_on_publish' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement