这不起作用:
警告:in\\u array()要求参数2为数组,给定null
$non_area_page = array(160951,160955); // This does not work
add_filter( \'term_link\',change_term_name , 10, 3 );
function change_term_name( $termlink, $term, $taxonomy )
{
/*If on page */
if(is_page()){
$current_id = get_queried_object_id();
$current_post = get_post($current_id);
$slug = $current_post->post_name;
if(!in_array($current_id,$non_area_page)) // array is defined in start of code above
$termlink = esc_url( add_query_arg( [\'tag\' => $slug], $termlink ) );
}
return $termlink;
}
下面的代码起作用:(唯一的区别是数组没有在函数外定义)add_filter( \'term_link\',change_term_name , 10, 3 );
function change_term_name( $termlink, $term, $taxonomy )
{
/*If on page */
if(is_page()){
$current_id = get_queried_object_id();
$current_post = get_post($current_id);
$slug = $current_post->post_name;
if(!in_array($current_id,array(160951,160955))) // directly passed array
$termlink = esc_url( add_query_arg( [\'tag\' => $slug], $termlink ) );
}
return $termlink;
}
这是否与全局定义数组有关,如果是,请建议我们如何在WordPress中这样做?谢谢