From 21b7e67c46fbac3c6cf18ef1da7c9e416b5f3b17 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 17 Nov 2020 17:42:14 +0200 Subject: [PATCH] Add missing piece for post-meta to tax refactor (#27042) --- lib/templates.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/templates.php b/lib/templates.php index 41bdc75d22fe8..707e443aa627b 100644 --- a/lib/templates.php +++ b/lib/templates.php @@ -120,10 +120,15 @@ function gutenberg_set_template_post_theme( $post_id, $post, $update ) { return; } - $theme = get_post_meta( $post_id, 'theme', true ); + $wp_theme_term = get_term_by( 'slug', wp_get_theme()->get_stylesheet(), 'wp_theme' ); + if ( $wp_theme_term ) { - if ( ! $theme ) { - update_post_meta( $post_id, 'theme', wp_get_theme()->get_stylesheet() ); + // If the term was found, assign it to this post. + wp_set_object_terms( $post_id, $wp_theme_term->term_id, 'wp_theme' ); + } else { + + // Using a string instead of integer will create the term and assign it to the post. + wp_set_object_terms( $post_id, wp_get_theme()->get_stylesheet(), 'wp_theme' ); } }