Wordpress 对于自定义分类法,我可以使用什么来代替获取
基本上,我在WordPress中创建了一个带有自定义分类法(custom_tax)的自定义帖子类型。现在我已经创建了一个自定义查询,我想在其中获取保存自定义帖子的自定义类别,并将其名称作为字符串输出。我在使用WordPress标准分类法时这样做:Wordpress 对于自定义分类法,我可以使用什么来代替获取,wordpress,custom-post-type,custom-taxonomy,Wordpress,Custom Post Type,Custom Taxonomy,基本上,我在WordPress中创建了一个带有自定义分类法(custom_tax)的自定义帖子类型。现在我已经创建了一个自定义查询,我想在其中获取保存自定义帖子的自定义类别,并将其名称作为字符串输出。我在使用WordPress标准分类法时这样做: //Start the query query_posts(array( 'showposts' => $posts, 'orderby' => 'asc', 'category_name' => $category
//Start the query
query_posts(array(
'showposts' => $posts,
'orderby' => 'asc',
'category_name' => $category
));
$temp_title = get_the_title();
$temp_link = get_permalink();
$temp_excerpt = get_the_excerpt();
$temp_time = get_the_date('Y-m-d');
$temp_categories = get_the_category(', ');
$temp_author = get_the_author();
$temp_content = get_the_content();
$i++;
$output2 .= "<li class='item' data-id='id-" . $i . "' data-type='" . $temp_categories . "'><a href='" . $temp_link . "' rel='prettyPhoto[portfolio]'><img class='' src='" . $path . "/library/timthumb.php?src=" . $image[0] . "&h=130&w=210&zc=1&q=100' alt='" . $temp_title . "' /></a></li>";
//启动查询
查询职位(数组)(
“showposts”=>$posts,
'orderby'=>'asc',
“类别名称”=>$category
));
$temp_title=获取_title();
$temp_link=get_permalink();
$temp_extract=获取_摘录();
$temp_time=获取日期('Y-m-d');
$temp_categories=获取_类别(',');
$temp_author=获取_作者();
$temp_content=获取_内容();
$i++;
$output2.=“”;
它就像一个符咒。现在,我需要使用自定义帖子和自定义分类法,并尝试了许多不同的方法:
//Start the query
query_posts(array(
'post_type' => array('post', 'portfolio'),
'showposts' => $posts,
'orderby' => 'asc',
'category_name' => $category
));
$temp_title = get_the_title();
$temp_link = get_permalink();
$temp_excerpt = get_the_excerpt();
$temp_time = get_the_date('Y-m-d');
$temp_categories = get_the_terms( get_the_ID(), 'custom_cat', ', ' );
$temp_author = get_the_author();
$temp_content = get_the_content();
$i++;
$output2 .= "<li class='item' data-id='id-" . $i . "' data-type='" . $temp_categories . "'><a href='" . $temp_link . "' rel='prettyPhoto[portfolio]'><img class='' src='" . $path . "/library/timthumb.php?src=" . $image[0] . "&h=130&w=210&zc=1&q=100' alt='" . $temp_title . "' /></a></li>";
//启动查询
查询职位(数组)(
'post_type'=>数组('post','portfolio'),
“showposts”=>$posts,
'orderby'=>'asc',
“类别名称”=>$category
));
$temp_title=获取_title();
$temp_link=get_permalink();
$temp_extract=获取_摘录();
$temp_time=获取日期('Y-m-d');
$temp_categories=获取_术语(获取_ID(),'custom_cat',',');
$temp_author=获取_作者();
$temp_content=获取_内容();
$i++;
$output2.=“”;
但它不起作用。我曾经尝试过get_the_terms()、the_terms()和get_terms(),但是没有一个像get_the_category()那样工作——它输出了一个带有类别名称的字符串。我错过了什么
非常感谢Wordpress将分类法描述为“术语”。关于“get_terms()”的文档中可能有一些帮助。如果您想按术语排序,有一种方法可以做到这一点 谢谢你,马修。我以前看过get_terms(),输出结果与我需要的不同。我只需要这个特殊的职位是保存在类别下显示在其他地方的职位。