Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取自定义帖子类型的分类值_Php_Wordpress_Custom Post Type_Custom Taxonomy - Fatal编程技术网

Php 如何获取自定义帖子类型的分类值

Php 如何获取自定义帖子类型的分类值,php,wordpress,custom-post-type,custom-taxonomy,Php,Wordpress,Custom Post Type,Custom Taxonomy,我正在创建一个新模板,该模板将获取所有自定义帖子类型(案例研究)内容,包括与之关联的分类法值 到目前为止,我得到了以下信息: <section> <h1><?php _e( 'posts', 'casestudies' ); ?></h1> <?php get_template_part('loop'); ?> <?php $args = array('post_type' => 'casestudies', 'posts_

我正在创建一个新模板,该模板将获取所有自定义帖子类型(案例研究)内容,包括与之关联的分类法值

到目前为止,我得到了以下信息:

<section>
<h1><?php _e( 'posts', 'casestudies' ); ?></h1>
<?php get_template_part('loop'); ?>
<?php
$args = array('post_type' => 'casestudies', 'posts_per_page' => 3);
$query = new WP_Query($args);
while($query -> have_posts()) : $query -> the_post();
?>
<h2><?php the_title(); ?></h2>
<p>Meta: <?php the_meta(); ?></p>
<p>Excerpt: <?php the_excerpt(); ?></p>
<p>what_to_put_here_to_get_taxonomies_values????</p>
<?php endwhile; ?>

<?php get_template_part('pagination'); ?>
</section>

元:

摘录:

把什么放在这里,得到分类法和价值观


我如何得到它的分类法?我尝试了多种方法,但都失败了,只是变得更加困惑。

您是否尝试过使用


如果要查找特定的分类法,该函数具有可选参数,则可以传入以控制输出。请参阅此处的文档:

检查此功能:

假设您的自定义post类型案例研究支持两种称为country和subject的分类法,您可以尝试以下方法:

<?php $terms = wp_get_post_terms( $query->post->ID, array( 'country', 'subject' ) ); ?>
<?php foreach ( $terms as $term ) : ?>
<p><?php echo $term->taxonomy; ?>: <?php echo $term->name; ?></p>
<?php endforeach; ?>

假设:我使用自定义的post类型名称publication\u category注册了一个分类法

在自定义帖子类型模板上写:

$terms = get_the_terms( $post->ID, 'publication_category' );
if ($terms) {
    foreach($terms as $term) {
      echo $term->name;
    } 
}

为了以防万一,如果它能帮助某人,我在自定义post类型的循环中使用了“theu taxonomies()”函数

        <?php

        while ( have_posts() ) : the_post();    
          $custom_post = get_post_meta( get_the_ID() );       
          //
        ?>

        //html
        //and stuff

        <?php the_taxonomies(); ?>

        <?php
          endwhile;
        ?>


 the result was:

   Taxonomy-name: {Taxonomy-term}. <-- as a link

//html
//诸如此类
结果是:

分类名称:{Taxonomy term}。我的最终代码如下所示:Meta:

摘录:

        <?php

        while ( have_posts() ) : the_post();    
          $custom_post = get_post_meta( get_the_ID() );       
          //
        ?>

        //html
        //and stuff

        <?php the_taxonomies(); ?>

        <?php
          endwhile;
        ?>


 the result was:

   Taxonomy-name: {Taxonomy-term}. <-- as a link