wp_set_post_terms example

/* translators: %s: Taxonomy name. */
                _doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid taxonomy: %s.' )$taxonomy ), '4.4.0' );
                continue;
            }

            // array = hierarchical, string = non-hierarchical.             if ( is_array( $tags ) ) {
                $tags = array_filter( $tags );
            }

            if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
                wp_set_post_terms( $post_id$tags$taxonomy );
            }
        }
    }

    if ( ! empty( $postarr['meta_input'] ) ) {
        foreach ( $postarr['meta_input'] as $field => $value ) {
            update_post_meta( $post_id$field$value );
        }
    }

    $current_guid = get_post_field( 'guid', $post_id );

    
if ( ! $post->post_name ) {
        wp_update_post(
            array(
                'ID'        => $post_id,
                'post_name' => 'custom_slug_' . uniqid(),
            )
        );
    }

    $terms = get_the_terms( $post_id, 'wp_theme' );
    if ( ! is_array( $terms ) || ! count( $terms ) ) {
        wp_set_post_terms( $post_idget_stylesheet(), 'wp_theme' );
    }
}

/** * Generates a unique slug for templates. * * @access private * @since 5.8.0 * * @param string $override_slug The filtered value of the slug (starts as `null` from apply_filter). * @param string $slug The original/un-filtered slug (post_name). * @param int $post_id Post ID. * @param string $post_status No uniqueness checks are made if the post is still draft or pending. * @param string $post_type Post type. * @return string The original, desired slug. */


    if ( ! empty( $format ) ) {
        $format = sanitize_key( $format );
        if ( 'standard' === $format || ! in_array( $formatget_post_format_slugs(), true ) ) {
            $format = '';
        } else {
            $format = 'post-format-' . $format;
        }
    }

    return wp_set_post_terms( $post->ID, $format, 'post_format' );
}

/** * Returns an array of post format slugs to their translated and pretty display versions * * @since 3.1.0 * * @return string[] Array of post format labels keyed by format slug. */
function get_post_format_strings() {
    $strings = array(
        
Home | Imprint | This part of the site doesn't use cookies.