rveitch
3/18/2016 - 5:42 PM

Open Byline Author - Say Anything - Remove "Rob Port" (admin slug) from imported posts

Open Byline Author - Say Anything - Remove "Rob Port" (admin slug) from imported posts

<?php
global $post;
$oba_slug = 'admin';

// WP_Query arguments
$args = array (
	'post_type'              => array( 'post' ),
	'post_status'            => array( 'publish' ),
	'posts_per_page'         => '1000',
	'tax_query' => array(
		array(
			'taxonomy' => 'open_byline_author',
			'field'    => 'slug',
			'terms'    => $oba_slug,
		),
	),
	'date_query' => array(
		array(
			'before'     => 'January 1st, 2016',
			'inclusive' => true,
		),
	),
);

// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
	while ( $query->have_posts() ) {
		$query->the_post();
		// do something
		$id = (int) $post->ID;
		
		# Remove Term
        wp_remove_object_terms( $id, $oba_slug, 'open_byline_author' );
        echo 'Term Removed from post ' . $id . '<br>';
		
		//echo '<pre>';
		//echo $id . '<br>';
		//print_r($post);
		//echo '</pre>';
	}
} else {
	// no posts found
}

// Restore original Post Data
wp_reset_postdata();