首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >acf出租车cpt

acf出租车cpt
EN

WordPress Development用户
提问于 2019-03-20 16:27:57
回答 1查看 160关注 0票数 0

我有个CPT的“编队”。在我的一个编队(single.php)的页面中有一节“其他文章”。我想从我的编辑的每一个“形成”页面,选择类别,以显示其他“形成”的愿望。我的分类法列表被创建了。目前,它们处于一个循环的archive.php外观结构中(它们都会出现)。

结论:在我的“编队”页面上,我希望能够检查必须出现在页面上的“其他格式”块中的文章类别。

我应该如何放置和或我的分类ACF循环为我的文章出现。现在,我用ACF字段类型创建了metabox :分类法&我的分类法名"Thematiques“

我的代码:mon-formation.php

代码语言:javascript
复制
                 'formation');?>
            
                 have_posts()): $loop->the_post();?>
                
                    
                    
                        
                        
                        
                        En savoir plus

我的代码: functions.php

代码语言:javascript
复制
    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');
EN

回答 1

WordPress Development用户

回答已采纳

发布于 2019-03-20 23:08:53

您可能希望使用ACF分类法字段的值作为WP_Query的附加参数。因此,在“单表单.this”中,将WP_Query替换为如下所示:

代码语言:javascript
复制
$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的“构造”,并选择“主题式”分类法的术语。

票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/332183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档