如何使用WordPress的register_taxonomy_args过滤分类参数

问题描述 投票:0回答: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

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

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

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

我的过滤功能

<?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' );
?>

我做错了什么?谢谢。

php wordpress wordpress-theming custom-taxonomy wordpress-hook
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 );
?>
© www.soinside.com 2019 - 2024. All rights reserved.