以编程方式将元键和元值添加到 wordpress 中的 post (woocommerce)
add meta key and meta value to post in wordpress programmatically (woocommerce)
我想在 wordpress post 中为 woocommerce 产品添加自定义元键和元值。我有这样的代码:
global $wpdb;
$post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts ORDER BY ID DESC LIMIT 1" );
add_post_meta($post_id, 'offers_for_woocommerce_enabled', 'yes’, true);
add_post_meta($post_id, 'woo_ua_product_condition', 'used', true);
add_post_meta($post_id, 'woo_ua_opening_price', 1, true);
add_post_meta($post_id, 'woo_ua_lowest_price', 2, true);
并且我收到了错误:解析错误:语法错误,意外 'woo_ua_product_condition' (T_STRING),期待 ')' 在 ...
请帮忙
你在这一行有不同的引号add_post_meta($post_id, 'offers_for_woocommerce_enabled', 'yes’, true);
替换成这个
add_post_meta($post_id, 'offers_for_woocommerce_enabled', 'yes', true);
我想在 wordpress post 中为 woocommerce 产品添加自定义元键和元值。我有这样的代码:
global $wpdb;
$post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts ORDER BY ID DESC LIMIT 1" );
add_post_meta($post_id, 'offers_for_woocommerce_enabled', 'yes’, true);
add_post_meta($post_id, 'woo_ua_product_condition', 'used', true);
add_post_meta($post_id, 'woo_ua_opening_price', 1, true);
add_post_meta($post_id, 'woo_ua_lowest_price', 2, true);
并且我收到了错误:解析错误:语法错误,意外 'woo_ua_product_condition' (T_STRING),期待 ')' 在 ...
请帮忙
你在这一行有不同的引号add_post_meta($post_id, 'offers_for_woocommerce_enabled', 'yes’, true);
替换成这个
add_post_meta($post_id, 'offers_for_woocommerce_enabled', 'yes', true);