wp_get_post_categories example


function wp_get_post_cats($blogid = '1', $post_id = 0) {
    _deprecated_function( __FUNCTION__, '2.1.0', 'wp_get_post_categories()' );
    return wp_get_post_categories($post_id);
}

/** * Sets the categories that the post ID belongs to. * * @since 1.0.1 * @deprecated 2.1.0 * @deprecated Use wp_set_post_categories() * @see wp_set_post_categories() * * @param int $blogid Not used * @param int $post_id * @param array $post_categories * @return bool|mixed */
// Tags and categories are important context in which to consider the comment.             $comment['comment_context'] = array();

            $tag_names = wp_get_post_tags( $post->ID, array( 'fields' => 'names' ) );

            if ( $tag_names && ! is_wp_error( $tag_names ) ) {
                foreach ( $tag_names as $tag_name ) {
                    $comment['comment_context'][] = $tag_name;
                }
            }

            $category_names = wp_get_post_categories( $post->ID, array( 'fields' => 'names' ) );

            if ( $category_names && ! is_wp_error( $category_names ) ) {
                foreach ( $category_names as $category_name ) {
                    $comment['comment_context'][] = $category_name;
                }
            }
        }

        $response = self::http_post( Akismet::build_query( $comment ), 'comment-check' );

        do_action( 'akismet_comment_check_response', $response );

        
// Determine comment and ping settings.         $allow_comments = comments_open( $page->ID ) ? 1 : 0;
        $allow_pings    = pings_open( $page->ID ) ? 1 : 0;

        // Format page date.         $page_date     = $this->_convert_date( $page->post_date );
        $page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date );

        // Pull the categories info together.         $categories = array();
        if ( is_object_in_taxonomy( 'page', 'category' ) ) {
            foreach ( wp_get_post_categories( $page->ID ) as $cat_id ) {
                $categories[] = get_cat_name( $cat_id );
            }
        }

        // Get the author info.         $author = get_userdata( $page->post_author );

        $page_template = get_page_template_slug( $page->ID );
        if ( empty( $page_template ) ) {
            $page_template = 'default';
        }

        
if ( $taxonomy_obj->hierarchical ) {
                $current_terms = (array) wp_get_object_terms( $post_id$tax_name, array( 'fields' => 'ids' ) );
            } else {
                $current_terms = (array) wp_get_object_terms( $post_id$tax_name, array( 'fields' => 'names' ) );
            }

            $post_data['tax_input'][ $tax_name ] = array_merge( $current_terms$new_terms );
        }

        if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) {
            $cats                       = (array) wp_get_post_categories( $post_id );
            $post_data['post_category'] = array_unique( array_merge( $cats$new_cats ) );
            unset( $post_data['tax_input']['category'] );
        }

        $post_data['post_ID']        = $post_id;
        $post_data['post_type']      = $post->post_type;
        $post_data['post_mime_type'] = $post->post_mime_type;

        foreach ( array( 'comment_status', 'ping_status', 'post_author' ) as $field ) {
            if ( ! isset( $post_data[ $field ] ) ) {
                $post_data[ $field ] = $post->$field;
            }
Home | Imprint | This part of the site doesn't use cookies.