Thread Starter
meeper
(@meeper)
Have found this snippet:(query for text ‘test’)
$query = new WP_Query( 's=test' );
if ($query->have_posts()){
while ( $query->have_posts() ) { $query->the_post();
echo 'Text has been inserted at '. the_title();
// or insert function for adding this to simple history alert
}
}
Thanks for the link you provided. Although, now, it’s led to more questions.
I think it’s a bit out of scope for this support forum,
but what you probably need to do is to run that code for example every hour and then when a matching post is found then you can log that info to simple history using something like:
SimpleLogger()->info("Found a post containing test. Post id is {post_id}", array(
"post_id" => get_the_id()
));
Good luck!
Thread Starter
meeper
(@meeper)
Thanks for the speedy reply!
Am I right in adding this to functions.php, instead of creating a simple logger extension? Used the code below. Nothing so far. Tried the email notif earlier, resulted to an infinite loop.
//* Send alert if text is inserted
function custom_text_string_alert( $post_id ) {
// If this is just a revision, don't send the email.
if ( wp_is_post_revision( $post_id ) )
return;
$query = new WP_Query( 's=staging' );
if ($query->have_posts()){
while ( $query->have_posts() ) { $query->the_post();
//echo 'Text has been insert at '. the_title();
// or insert function for adding this to simple history alert
SimpleLogger()->info("Found a post containing test. Post id is {post_id}", array(
"post_id" => get_the_id()
));
}
}
}
add_action( 'save_post', 'custom_text_string_alert' );