我正在开始使用高级自定义字段。我有一个类别字段(main\\u category),其中使用单选按钮选择下面给出的类别。
1. Electronics
2. Programming
3. Design
其中有这些类别的子类别。它们是使用每个类别的条件单选按钮设置的。子类别被编入索引,字段被赋予离子括号,
Post Type: article
Field Name: Category
Field key : main_category
1. Electronics - - - - - - - - (electronics)
Linear Electronics - - (elect_linear)
Computer Networks- - - (elect_networks)
Microwave Engineering- (elect_microwave)
MicroProcessors- - - - (elect_micropro)
2. Programming - - - - - - - - (programming)
ObjectiveC - - - - - - (prog_objc)
Pythion - - - - - - - (prog_python)
JavaScript - - - - - - (prog_js)
PHP - - - - - - - - - (prog_php)
3. Design - - - - - - - - (design)
Illustrator - - - - - (desgn_ai)
Photoshop - - - - - - (desgn_ps)
After Effects - - - - (desgn_ae)
Cinema 4d - - - - - - (desgn_cf)
进行了WP\\U查询,
$articles = array(
\'numberposts\' => -1,
\'post_type\' => \'article\',
\'meta_key\' => \'main_category\',
);
$query_articles = new WP_Query( $articles);
它返回了一个数组$query\\u articles,其中包含所有帖子。,如何筛选数组$query\\u文章?因此,我会为php子类别中的文章添加“在php中标记”。?
据我所知,我所能做的就是查询具有不同类别的数组。。
$electronics = array(
\'numberposts\' => -1,
\'post_type\' => \'article\',
\'meta_key\' => \'main_category\',
\'meta_value\' => \'electronics\'
);
$programming = array(
\'numberposts\' => -1,
\'post_type\' => \'article\',
\'meta_key\' => \'main_category\',
\'meta_value\' => \'programming\'
);
$design = array(
\'numberposts\' => -1,
\'post_type\' => \'article\',
\'meta_key\' => \'main_category\',
\'meta_value\' => \'design\'
);
//query variables
$query_electronics = new WP_Query( $electronics);
$query_programming = new WP_Query( $programming);
$query_design = new WP_Query( $design );
但是,子类别总是一团糟,而且它也占用了大量资源。
附:这是我在localhost中开发的一个博客。感谢您的帮助和评论。