Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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 按当前帖子ID排除术语(类别名称)_Php_Wordpress_Categories_Taxonomy_Term - Fatal编程技术网

Php 按当前帖子ID排除术语(类别名称)

Php 按当前帖子ID排除术语(类别名称),php,wordpress,categories,taxonomy,term,Php,Wordpress,Categories,Taxonomy,Term,我发现这个函数可以显示附加到帖子的术语,但是我无法找到一种方法来排除一些我不想在列表中显示的类别术语的特定ID。 有人能给我一个开始的线索吗?我查找了此函数中使用的所有函数,但似乎找不到排除id的参数 提前谢谢 // get taxonomies terms links function custom_taxonomies_terms_links() { global $post, $post_id; // get post by post id $post = &

我发现这个函数可以显示附加到帖子的术语,但是我无法找到一种方法来排除一些我不想在列表中显示的类别术语的特定ID。 有人能给我一个开始的线索吗?我查找了此函数中使用的所有函数,但似乎找不到排除id的参数

提前谢谢

   // get taxonomies terms links
   function custom_taxonomies_terms_links() {
   global $post, $post_id;
   // get post by post id
   $post = &get_post($post->ID);
   // get post type by post
   $post_type = $post->post_type;
   // get post type taxonomies
   $taxonomies = get_object_taxonomies($post_type);
   $out = "<ul>";
   foreach ($taxonomies as $taxonomy) {        
       // get the terms related to post
       $terms = get_the_terms( $post->ID, $taxonomy );
       if ( !empty( $terms ) ) {
           foreach ( $terms as $term )
               $out .= '<li><a href="' .get_term_link($term->slug, $taxonomy) .'">'.$term->name.'</a></li> ';
        }
    }
    $out .= "</ul>";
    return $out;
} 
//获取分类术语链接
函数自定义\分类\术语\链接(){
全局$post,$post\u id;
//通过邮寄id获取邮寄
$post=&get\u post($post->ID);
//通过邮寄获取邮件类型
$post\U type=$post->post\U type;
//获取post类型分类法
$taxonomies=get\u object\u分类法($post\u type);
$out=“
    ”; foreach($taxonomy作为$taxonomy){ //获取与post相关的术语 $terms=获取术语($post->ID,$taxonomy); 如果(!空($terms)){ foreach($terms作为$term) $out.='
  • '; } } $out.=“
”; 退回$out; }
在第二个
foreach()
中添加另一个条件
if
语句,以检查是否应忽略
$term
。例如:

// An array of IDs to ignore/exclude
$excluded_ids = array( 1, 2, 3, 4);

foreach ( $terms as $term ) {
    // Only proceed if the term_id is NOT in the $excluded_ids array
    if ( !in_array( $term->term_id, $excluded_ids ) ) {
        $out .= '<li><a href="' .get_term_link($term->slug, $taxonomy) .'">'.$term->name.'</a></li> ';
    }
}
//要忽略/排除的ID数组
$excluded_id=数组(1,2,3,4);
foreach($terms作为$term){
//仅当术语_id不在$excluded_id数组中时才继续
if(!in_数组($term->term_id,$excluded_id)){
$out.='
  • '; } }
    嘿,谢谢你的快速回复。但是当我输入不同的id时,我不想看到它只显示我想排除的类别名称的名称,这不应该发生。听起来你好像错过了
    在数组中的
    之前(
    好,很抱歉我做错了:)。它工作完美!非常感谢!!