Пример #1
0
function relevanssi_update_child_posts($new_status, $old_status, $post)
{
    // called by 'transition_post_status' action hook when a post is edited/published/deleted
    //  and calls appropriate indexing function on child posts/attachments
    global $wpdb;
    // Safety check, for WordPress Editorial Calendar incompatibility
    if (!isset($post) || !isset($post->ID)) {
        return;
    }
    $index_statuses = apply_filters('relevanssi_valid_status', array('publish', 'private', 'draft', 'pending', 'future'));
    if ($new_status == $old_status || in_array($new_status, $index_statuses) && in_array($old_status, $index_statuses) || in_array($post->post_type, array('attachment', 'revision'))) {
        return;
    }
    $q = "SELECT * FROM {$wpdb->posts} WHERE post_parent={$post->ID} AND post_type!='revision'";
    $child_posts = $wpdb->get_results($q);
    if ($child_posts) {
        if (!in_array($new_status, $index_statuses)) {
            foreach ($child_posts as $post) {
                relevanssi_delete($post->ID);
            }
        } else {
            foreach ($child_posts as $post) {
                relevanssi_publish($post->ID);
            }
        }
    }
}
Пример #2
0
function relevanssi_update_child_posts($new_status, $old_status, $post) {
// called by 'transition_post_status' action hook when a post is edited/published/deleted
//  and calls appropriate indexing function on child posts/attachments
    global $wpdb;
    $index_statuses = array('publish', 'private');
    if (($new_status == $old_status)
          || (in_array($new_status, $index_statuses) && in_array($old_status, $index_statuses))
          || (in_array($post->post_type, array('attachment', 'revision')))) {
        return;
    }
    $q = "SELECT * FROM $wpdb->posts WHERE post_parent=$post->ID AND post_type!='revision'";
    $child_posts = $wpdb->get_results($q);
    if ($child_posts) {
        if (!in_array($new_status, $index_statuses)) {
            foreach ($child_posts as $post) {
                relevanssi_delete($post->ID);
            }
        } else {
            foreach ($child_posts as $post) {
                relevanssi_publish($post->ID);
            }
        }
    }
}