wp_set_post_categories example

if ( $id ) {
            $cat_ids[] = $id;
        } else {
            $id = wp_create_category( $category );
            if ( $id ) {
                $cat_ids[] = $id;
            }
        }
    }

    if ( $post_id ) {
        wp_set_post_categories( $post_id$cat_ids );
    }

    return $cat_ids;
}

/** * Updates an existing Category or creates a new Category. * * @since 2.0.0 * @since 2.5.0 $wp_error parameter was added. * @since 3.0.0 The 'taxonomy' argument was added. * * @param array $catarr { * Array of arguments for inserting a new category. * * @type int $cat_ID Category ID. A non-zero value updates an existing category. * Default 0. * @type string $taxonomy Taxonomy slug. Default 'category'. * @type string $cat_name Category name. Default empty. * @type string $category_description Category description. Default empty. * @type string $category_nicename Category nice (display) name. Default empty. * @type int|string $category_parent Category parent ID. Default empty. * } * @param bool $wp_error Optional. Default false. * @return int|WP_Error The ID number of the new or updated Category on success. Zero or a WP_Error on failure, * depending on param `$wp_error`. */

function wp_set_post_cats($blogid = '1', $post_id = 0, $post_categories = array()) {
    _deprecated_function( __FUNCTION__, '2.1.0', 'wp_set_post_categories()' );
    return wp_set_post_categories($post_id$post_categories);
}

/** * Retrieves a list of archives. * * @since 0.71 * @deprecated 2.1.0 Use wp_get_archives() * @see wp_get_archives() * * @param string $type * @param string $limit * @param string $format * @param string $before * @param string $after * @param bool $show_post_count * @return string|null */


        if ( ! current_user_can( 'edit_post', $post_id ) ) {
            return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
        }

        $catids = array();
        foreach ( $categories as $cat ) {
            $catids[] = $cat['categoryId'];
        }

        wp_set_post_categories( $post_id$catids );

        return true;
    }

    /** * Retrieves an array of methods supported by this server. * * @since 1.5.0 * * @return array */
    
        $where = array( 'ID' => $post_id );
    }

    if ( empty( $data['post_name'] ) && ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ), true ) ) {
        $data['post_name'] = wp_unique_post_slug( sanitize_title( $data['post_title']$post_id )$post_id$data['post_status']$post_type$post_parent );

        $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] )$where );
        clean_post_cache( $post_id );
    }

    if ( is_object_in_taxonomy( $post_type, 'category' ) ) {
        wp_set_post_categories( $post_id$post_category );
    }

    if ( isset( $postarr['tags_input'] ) && is_object_in_taxonomy( $post_type, 'post_tag' ) ) {
        wp_set_post_tags( $post_id$postarr['tags_input'] );
    }

    // Add default term for all associated custom taxonomies.     if ( 'auto-draft' !== $post_status ) {
        foreach ( get_object_taxonomies( $post_type, 'object' ) as $taxonomy => $tax_object ) {

            if ( ! empty( $tax_object->default_term ) ) {

                
Home | Imprint | This part of the site doesn't use cookies.