wordpress - 根据帖子元自动选择分类
问题描述
我使用 jetengine 名称listing
为电子商务网站评论创建了一个自定义帖子类型,并且它有platform
一个下拉选择框。
此帖子类型具有称为payment method
&的分类法,shipping method
其中包含多个术语
因此,当我创建新帖子时,如果我选择A 那么它会自动在andplatform
中选择多个术语(复选框)吗?payment method
shipping method
如果平台是A,那么付款方式是银行转账,贝宝和运输方式是ups,fedex
如果平台是 B,那么付款方式是 paypal,信用卡和运输方式是 usps、dhl、fedex
提前致谢
解决方案
试试这个代码
您需要用您的数据填充 $data_array 并将分类 slug 更改为您的
add_action( 'save_post_listing', 'listing_save_payment_term' );
function listing_save_payment_term($post_id) {
$data_array = array(
"platform_name" => "payment method & shipping method terms_ids comma separated in array",
"platform_name2" => array( 15,12,18),
"platform_name3" => array( 19,18),
"platform_name4" => array( 19,18),
);
remove_action( 'save_post_listing', 'listing_save_payment_term' );
$meta = get_post_meta($post->ID, "platform", true);
if($meta != "") {
$platform_term_ids = $data_array[$meta];
if($platform_term_ids != "") {
//change here for your payment method & shipping method taxonomy slug
wp_set_object_terms($post_id, $platform_term_ids, 'payment method & shipping method slug');
}
clean_post_cache( $post_id );
} else {
//change here for your payment method & shipping method taxonomy slug
wp_delete_object_term_relationships( $post_id, 'payment method & shipping method slug' );
}
add_action( 'save_post_listing', 'listing_save_payment_term' );
}
推荐阅读
- css - 当我渲染内容时,我的页面在 React.js 中跳转?
- c - 字典找不到拼写错误的单词
- mysql - mysql order by field row display 即使为空
- kubernetes - Kubernetes Helm PVC
- amazon-web-services - AWS 如何使用 ALB 和 ECS 实现超高可用性应用程序
- c# - 库之间的区别:Microsoft.Azure.EventGrid 和 Azure.Messaging.EventGrid
- python - DJANGO:如何渲染 swagger-codegen 模型对象而不是数据库模型对象
- amazon-web-services - 成云模板中如何根据阶段设置环境变量
- php - 如何解决致命错误:未捕获的错误?
- android - 为什么 Android Studio 在 View -> Tool Windows 中缺少“调色板”?