J'essaie d'ajouter un nouveau portfolio de façon pragmatique lorsque j'ajoute une nouvelle catégorie dans WooCommerce.Obtention de l''identifiant de vignette' du terme de la dernière catégorie de produits dans WooCommerce
Mon code est:
function programmatically_create_post() {
$author_id = 1;
$taxonomy = 'product_cat';
$orderby = 'id';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$all_categories = get_categories($args);
$lastCategory=end($all_categories);
$slug =$lastCategory->slug;
$title=$lastCategory->name;
$thumbnail_id= get_post_thumbnail_id($lastCategory->id);
// If the page doesn't already exist, then create it
if(null == get_page_by_title($title)) {
// Set the post ID so that we know the post was created successfully
$post_id = wp_insert_post(
array(
'post_author' => $author_id,
'post_name' => $slug,
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'us_portfolio',
'post_parent' =>11,
'page_template' =>'custumcat.php',
'post_slug'=> $slug
)
);
update_post_meta($post_id, '_wp_page_template', 'custumcat.php');
update_post_meta($post_id, '_thumbnail_id', $thumbnail_id);
// Otherwise, we'll stop
} else {
// Arbitrarily use -2 to indicate that the page with the title already exists
$post_id = -2;
} // end if
} // end programmatically_create_post
add_action('create_product_cat', 'programmatically_create_post', 10,2);
Je veux miniature ensemble du portefeuille de la catégorie miniature, et je l'ai utilisé pour $thumbnail_id= get_post_thumbnail_id($lastCategory->id);
get catégorie miniature.
Ensuite, j'ai utilisé update_post_meta($post_id, '_thumbnail_id', $thumbnail_id);
pour définir la vignette du portefeuille.
Mais cela ne règle rien.
Comment puis-je résoudre ce problème?
Je l'ai édité. Mais il ne corrige pas –
obtenir l'erreur pour get_woocommerce_term_meta. –
Dans phpstorme drow une ligne sur get_woocommerce_term_meta, mais cela fonctionne et je reçois l'ID de la vignette, mais il ne se trouve pas sur la page de portefeuille –