Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Batch keep running over 100% #15

Open
gianghl1983 opened this issue Jan 21, 2021 · 2 comments
Open

The Batch keep running over 100% #15

gianghl1983 opened this issue Jan 21, 2021 · 2 comments

Comments

@gianghl1983
Copy link

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.
	}

}
@ivanbrkic
Copy link

Same here.

@dustyf
Copy link

dustyf commented Dec 21, 2021

I have been having this issue too. I am updating ~3000 posts, only if they do not have a certain meta value. Once they are updated that meta value is added. When it updates the Total # goes down.

Problem is that every time it runs to update the number processed it runs the setup method again and the query again which then updates the total number. The % then takes the Processed # / Total # to get the % complete. It does what it's supposed to do, but the visual feedback is then incorrect.

I guess the fix, be it when you are creating the batch, or something the author of the plugin adds, is to make sure whatever query you run in setup is only ran once and saved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants