Skip to content

The Batch keep running over 100% #15

Description

@gianghl1983

Hi,

I am trying with simple delete post like this, but the batch keep running even reach 100%...

Please check that...!

public function setup() {

		$posts = get_posts( array(
			'numberposts'      => 10,
			'post_type'   => 'it24-serial-number'
		) );

		foreach ( $posts as $post ) {
			$this->push( new WP_Batch_Item( $post->ID, array( 'post_id' => $post->ID ) ) );
		}
	}

public function process( $item ) {

		// Retrieve the custom data
		$post_id = $item->get_value( 'post_id' );
		

		// Return WP_Error if the item processing failed (In our case we simply skip author with user id 5)
		// if ( $post_id != 5 ) {
		// 	return new WP_Error( 302, "ID".$post_id );
		// }

		// Do the expensive processing here. eg. Sending email.
		// ...
		**wp_trash_post($post_id);**
		
		// Return true if the item processing is successful.
		return true;
	}

	/**
	 * Called when specific process is finished (all items were processed).
	 * This method can be overriden in the process class.
	 * @return void
	 */
	public function finish() {
		// Do something after process is finished.
		// You have $this->items, or other data you can set.
	}

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions