所以我在一个医疗网站上工作,这个网站有一个自定义的帖子类型“医生”。在这个帖子类型中,有“位置”和“过程”的自定义分类法。我已经创建了一个自定义分类位置。php文件来控制我的位置页面的外观,在这个页面上是一些一般信息,如联系信息、地图、相关医生。我还需要列出每个地点提供的所有程序。由于程序附加到每个医生,而不是每个位置,因此我创建了一个函数,其中包含一个循环,用于遍历当前位置标记的所有医生,并输出一个逗号分隔的所有标记程序术语ID列表。见下文:
// Get the doctors procedures
function location_doctors_procedure_loop() {
$tax_slug = get_query_var( \'locations\' );
$args = array(
\'posts_per_page\' => -1,
\'order\' => \'DESC\',
\'post_type\' => \'our_team\',
\'locations\' => $tax_slug
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
$terms = get_the_terms( $post, \'procedures\' );
if ( !empty($terms) ) {
foreach( $terms as $term ) {
echo $term->term_id . \',\';
}
}
}
wp_reset_postdata();
}
}
然后,我创建了一个函数,该函数循环遍历所有活动过程分类,并将它们按层次列出为父、子、祖父母。见下文:// Get the procedures
function tax_location_procedures() {
$doctor_procedures = location_doctors_procedure_loop();
$terms = get_terms( array(
\'taxonomy\' => \'procedures\',
\'hide_empty\' => true,
\'include\' => array( $doctor_procedures ),
) );
echo \'<h2 class="doctor-bio-procedure-condition-header">Procedures</h2>\';
if ( !empty($terms) ) {
echo \'<div class="doctor-bio-procedures">\';
foreach( $terms as $term ) {
if( $term->parent == 0 ) {
?>
<p class="doctor-bio-procedure-condition-sub-header"><?php echo $term->name; ?></p>
<?php
echo \'<ul>\';
foreach( $terms as $childterm ) {
if($childterm->parent == $term->term_id) {
echo \'<li>\' . $childterm->name . \'</li>\';
echo \'<ul>\';
foreach( $terms as $grandchildterm ) {
if($grandchildterm->parent == $childterm->term_id) {
echo \'<li>\' . $grandchildterm->name . \'</li>\';
}
}
echo \'</ul>\';
}
}
echo \'</ul>\';
}
}
echo \'</div>\';
}
}
我要做的是使用我的第一个函数“location\\u doctors\\u procedure\\u loop()”填充“function tax\\u location\\u procedures()”中的“include”参数数组。我遇到的问题是,虽然“location\\u doctors\\u procedure\\u loop()”会回显一个逗号分隔的正确术语ID列表(例如231229),但它对我的“include”参数没有任何作用,因为它回显为字符串而不是整数,所以它的读数为\'include\' => array(\'231,229,\')
而不是\'include\' => array(231,229,)
我被困在这个问题上,已经花了一天的大部分时间试图让它正常工作。如果你们能提供任何帮助,我们将不胜感激。