我想获得循环中帖子的类别列表。通常,我会使用
the_category(\', \');
但这确实输出了一个链接,我只想要类别名称。有什么想法吗?我想获得循环中帖子的类别列表。通常,我会使用
the_category(\', \');
但这确实输出了一个链接,我只想要类别名称。有什么想法吗?我想应该很容易。。
<?php
foreach((get_the_category()) as $category) {
//this would print cat names.. You can arrange in list or whatever you want..
echo \'<span>\'.$category->cat_name .\'</span>\';
}
?>
Without a loop
get_the_category_list(\',\');
下面的代码可能在循环之外有所帮助。我正在使用它save_post
行动挂钩。
// get the assigned terms to the post
$terms = get_the_terms( $post_id, \'category\' );
// create an empty array for storing category names
$terms_meta = [];
if ( ! empty( $terms ) ) {
foreach ( $terms as $term ) {
$terms_meta[] = $term->name;
}
}
if ( ! empty( $terms_meta ) ) {
$terms_string = implode( \', \', $terms_meta );
} else {
$terms_string = \'\';
}
print_r( $terms_string );
我的搜索表单中有wp\\u dropdown\\u categories函数。php文件。现在,它允许用户选择要搜索的帖子类别。有没有办法让下拉列表包含自定义分类法和自定义帖子类型?例如,如果我有一个用于图库的自定义帖子类型,以及一个用于位置的自定义分类法。。。如何显示wp下拉列表,让用户选择搜索“照片”或“位置”?