php - 如何按类别对自定义分类循环进行排序
问题描述
我创建了一个自定义分类法,它有各种不同的术语。基本上该月的所有帖子都分配给特定的术语,但此外所有帖子还分配有标准类别。
为自定义和税收创建模板并使用 WP_Query 我设法显示属于特定自定义税收的所有帖子。现在,我还希望按帖子类别对自定义税收循环中的所有帖子进行排序(例如,按经济、政治、技术等对帖子进行分组)。我曾尝试使用嵌套循环,但没有奏效。
对 php 来说非常新,任何帮助都非常有用。
<?php
$al_cat_slug = get_queried_object()->slug;
$al_cat_name = get_queried_object()->name;
?>
<h2><?php echo $al_cat_name; ?></h2>
<?php
$al_tax_post_args = array(
'post_type' => 'post',
'orderby' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'ausgabe',
'field' => 'slug',
'terms' => $al_cat_slug,
)
)
);
$query = new WP_Query($al_tax_post_args);
if ( $query->have_posts() ) { ?>
<section>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" class="fonds-article">
<h3 class="fonds-main-title"><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h3>
</article>
<?php endwhile; ?>
</section>
<?php } ?>
解决方案
推荐阅读
- matlab - 为 SIR 疾病模型绘制多条线
- java - 使用 Java 获取 Postgresql 过程签名详细信息
- npm-publish - 如何在不泄露代码的情况下将包发布到 npm
- javascript - 如何检测有多少 Rest items 可用
- c# - 如何获取 CurrentSetting.vssettings 的路径?
- c# - 如何在 mssql 中使用 sum() 函数和 where 条件?
- c# - 在回发之前删除 cookie
- jenkins - 带有 jenkins-shared-libraries 的通用管道
- android - 小米/Mi GetApps 我的应用程序的旧 apk 版本未在 Google Playstore 中显示更新选项
- node.js - 如何高效地进行多次 MongoDB 行程