Hi again @viktor Fröberg,
I’ve figured out that this is happening because of the save_post action hook being used to trigger rescraping. It runs whenever a post/page/CPT is created or updated, including auto-save drafts and revisions.
Thanks to this article, I thought that something like the following could be helpful:
function __construct(){
if( ! wp_is_post_revision( $post_id ) && ! wp_is_post_autosave( $post_id ) ) {
add_action( 'save_post', array($this, 'post_scraper'), 90, 2);
}
}
However, there are still some issues with this solution:
- I’m not sure if this works for taxonomy terms
- Rescraping still occurs on other undesirable post statuses (future, pending, draft, private…)
Ideally, the scraper would only run when a piece of content is first published (and the published status is “public”), and then afterwards whenever it is saved by pressing the Update button (and not for every auto-save, for which I believe the default interval is 1 minute, though I may be wrong since I’ve customized my setup).
So then I thought perhaps something like this:
function __construct(){
if( get_post_status ( $ID ) == 'publish' ) {
add_action( 'save_post', array($this, 'post_scraper'), 90, 2);
}
}
But I still don’t know if this would work for taxonomy terms. Moreover, I don’t know how this would handle the status transition from draft to published.
I’m fairly new at PHP, so I’d really appreciate if you could help me figure this out! Thanks 🙂