-
Hello, I want to manually trigger instant indexing API in my custom PHP function just like save_post.
Here my custom function code:
function ga_qse_update_slug() {
global $wpdb;$post_id = intval($_POST['post_id']);
$new_slug = sanitize_title($_POST['new_slug']);if (empty($post_id) || empty($new_slug)) {
wp_send_json_error('Invalid post ID or slug');
}// Check if the post exists
$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID = %d", $post_id));
if (is_null($post)) {
wp_send_json_error('Post not found');
}// Update the post slug
$result = $wpdb->update(
$wpdb->posts,
array('post_name' => $new_slug),
array('ID' => $post_id),
array('%s'),
array('%d')
);if ($result === false) {
wp_send_json_error('Database error: ' . $wpdb->last_error);
} elseif ($result === 0) {
wp_send_json_error('Failed to update slug');
} else {
wp_send_json_success('Slug updated successfully');
}
}Just like when I update posts and it automatically submits to the Instant Indexing API, the same i want it hereafter
wp_send_json_success('Slug updated successfully');
The ticket ‘Want to manually trigger Instant Indexing API in my function’ is closed to new replies.