【问题标题】:Wordpress display custom post type with custom taxonomy and current termWordpress 显示具有自定义分类和当前术语的自定义帖子类型
【发布时间】:2016-07-25 16:29:35
【问题描述】:

这道难点:

我正在尝试使用 custom taxonomy 'specialismen' 的 custom post type 'specialisaties' 中的所有帖子,并且需要加载当前加载的 '来自 URL 的术语'。

目前我有这段代码输出术语 'superpower' 。

<?php $loop = new WP_Query(array('post_type'=>'specialisaties', 'taxonomy'=>'specialismen', 'term' => 'superpower', 'orderby' => 'menu_order', 'order' => 'asc')); ?>
<?php while ($loop->have_posts()) : $loop->the_post();  ?>

    <h1><?php the_title() ?></h1>

    <?php the_content() ?>

    <?php endwhile; ?>

这会加载带有“超级大国”一词的特定帖子。如何从我正在加载的 URL 中动态获取“术语”?

提前致谢,

【问题讨论】:

    标签: wordpress custom-taxonomy


    【解决方案1】:

    用 get_term_by 修复它。

    <?php $term = get_term_by( 'slug', get_query_var('term'), get_query_var('taxonomy') ); ?>
    
    <?php $loop = new WP_Query(array('post_type'=>'specialisaties', 'taxonomy'=>'specialismen', 'term' => $term->name, 'orderby' => 'menu_order', 'order' => 'asc')); ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-03
      • 1970-01-01
      • 2018-01-08
      • 2013-03-08
      相关资源
      最近更新 更多