我有个CPT的“编队”。在我的一个编队(single.php)的页面中有一节“其他文章”。我想从我的编辑的每一个“形成”页面,选择类别,以显示其他“形成”的愿望。我的分类法列表被创建了。目前,它们处于一个循环的archive.php外观结构中(它们都会出现)。
结论:在我的“编队”页面上,我希望能够检查必须出现在页面上的“其他格式”块中的文章类别。
我应该如何放置和或我的分类ACF循环为我的文章出现。现在,我用ACF字段类型创建了metabox :分类法&我的分类法名"Thematiques“
我的代码:mon-formation.php
'formation');?>
have_posts()): $loop->the_post();?>
En savoir plus我的代码: functions.php
function custom_formation(){
$labels = array(
'name' => 'Formation',
'all_items' => 'Toutes les formations', // affiché dans le sous menu
'singular_name' => 'Formation',
'add_new_item' => 'Ajouter une formation',
'edit_item' => 'Modifier la formation',
'menu_name' => 'Formation'
);
$args = array(
'labels' => $labels,
'public' => true,
'show_in_rest' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor','thumbnail' ),
'menu_position' => 5,
'menu_icon' => 'dashicons-format-status',
);
register_post_type( 'formation', $args );
enter register_taxonomy(
'thematique',
'formation',
array(
'label' => 'Thématiques',
'labels' => array(
'name' => 'Thématiques',
'singular_name' => 'Thématiques',
'all_items' => 'Toutes les Thématiques',
'edit_item' => 'Éditer la Thématique',
'view_item' => 'Voir la Thématiques',
'update_item' => 'Mettre à jour la Thématiques',
'add_new_item' => 'Ajouter une Thématiques',
'new_item_name' => 'Nouvelle Thématiques',
'search_items' => 'Rechercher parmi les Thématiques',
'popular_items' => 'Thématiques les plus utilisés',
),
'hierarchical' => true,
'show_in_rest' => true,
'rewrite'=>false,
)
);
}
add_action('init','custom_formation');发布于 2019-03-20 23:08:53
您可能希望使用ACF分类法字段的值作为WP_Query的附加参数。因此,在“单表单.this”中,将WP_Query替换为如下所示:
$term_ids = get_field('taxonomy_field_name'); // make sure the return value of your ACF Taxonomy field is set to "Term ID"
$args = array(
'post_type' => 'formation',
'tax_query' => array(
array(
'taxonomy' => 'thematique',
'field' => 'term_id',
'terms' => $term_ids,
),
),
);
$loop = new WP_Query( $args );$loop现在应该包含任何CPT的“构造”,并选择“主题式”分类法的术语。
https://wordpress.stackexchange.com/questions/332183
复制相似问题