1

我正在尝试使用register_taxonomy_args过滤器钩子在选择的自定义分类法上过滤分类法参数。但是,这样做时,我会收到很多错误消息。

列举几个:

警告:第 278 行 /Applications/MAMP/htdocs/broadbean/wp-content/themes/scratch/functions.php 中的 edit_bb_taxonomy_args() 缺少参数 2

警告:第 278 行 /Applications/MAMP/htdocs/broadbean/wp-content/themes/scratch/functions.php 中的 edit_bb_taxonomy_args() 缺少参数 3

注意:未定义变量:第 280 行 /Applications/MAMP/htdocs/broadbean/wp-content/themes/scratch/functions.php 中的分类

警告:array_merge():参数 #2 不是第 379 行 /Applications/MAMP/htdocs/broadbean/wp-includes/taxonomy.php 中的数组

注意:未定义的索引:在第 398 行的 /Applications/MAMP/htdocs/broadbean/wp-includes/taxonomy.php 中重写

我的过滤功能

<?php
function edit_bb_taxonomy_args( $args, $taxonomy, $object_type ) {

    $taxonomies = array( 'wpbb_job_type', 'wpbb_job_location', 'wpbb_job_industry', 'wpbb_job_skill' );

    if ( in_array( $taxonomy, $taxonomies ) ) {
        $args = array(
            'with_front' => false
        );
        return $args;
    }
}
add_filter('register_taxonomy_args', 'edit_bb_taxonomy_args' );
?>

我究竟做错了什么?谢谢。

4

1 回答 1

3

不用担心我现在已经整理好了。

如果您有兴趣,解决方案如下...

<?php
function my_edit_bb_taxonomy_args( $args, $taxonomy, $object_type ) {

    $taxonomies = array( 'wpbb_job_type', 'wpbb_job_location', 'wpbb_job_industry', 'wpbb_job_skill' );
    if ( in_array( $taxonomy, $taxonomies ) ) {
        /* alter the rewrite with front arg */
        $args[ 'rewrite' ][ 'with_front' ] = false;
    }
    return $args;
}
add_filter( 'register_taxonomy_args', 'my_edit_bb_taxonomy_args', 10, 3 );
?>
于 2016-01-24T23:52:31.473 回答