Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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
wordpress在添加时获取术语标题_Wordpress - Fatal编程技术网

wordpress在添加时获取术语标题

wordpress在添加时获取术语标题,wordpress,Wordpress,我可能把术语弄混了,希望你能理解 我有一个自定义的“包”类型的帖子 我已经设置了创建名为“添加包类型”的分类的功能 当我添加一个类别时,我只希望在“添加包类型”中插入一个带有新类别标题的新页面 在$taxonomy中,我似乎无法使用下面的代码获得类别标题,我得到了“addpackagetype”,这很好。但我希望这一页与我刚才输入的标题同名 谢谢 function custom_create_packages( $term_id, $tt_id, $taxonomy ){ if($ta

我可能把术语弄混了,希望你能理解

我有一个自定义的“包”类型的帖子 我已经设置了创建名为“添加包类型”的分类的功能

当我添加一个类别时,我只希望在“添加包类型”中插入一个带有新类别标题的新页面

在$taxonomy中,我似乎无法使用下面的代码获得类别标题,我得到了“addpackagetype”,这很好。但我希望这一页与我刚才输入的标题同名

谢谢

function custom_create_packages( $term_id, $tt_id, $taxonomy ){

    if($taxonomy == 'package type'){
        $new_page_title = $cat_title;
        $new_page_content = 'This is the page content';
        $new_page_template = ''; //ex. template-custom.php. Leave blank if you don't want a custom page template.
        //don't change the code bellow, unless you know what you're doing
        $page_check = get_page_by_title($new_page_title);
        $new_page = array(
            'post_type' => 'page',
            'post_title' => $new_page_title,
            'post_content' => $new_page_content,
            'post_status' => 'publish',
            'post_author' => 1,
        );
        if(!isset($page_check->ID)){
            $new_page_id = wp_insert_post($new_page);
            if(!empty($new_page_template)){
                update_post_meta($new_page_id, '_wp_page_template', $new_page_template);
            }
        }
    }
}

add_action( 'create_term', 'custom_create_packages', 10, 3 );

如果我理解正确,您必须根据
$term\u id
参数检索术语的详细信息。比如:

function custom_create_packages( $term_id, $tt_id, $taxonomy ){

    if($taxonomy == 'package_type'){
        $term = get_term( $term_id, $taxonomy );
        $new_page_title = $term->name;
我不知道代码中的分类法slug(“包类型”)是否只是一个示例,但它不应该包含空格(请参阅)

可能值得将您的操作从
create_term
更改为
create_{taxonomy}
(例如
create_package_type
),以消除检查分类法的需要。请注意,
create{taxonomy}
只有两个参数(
$term\u id
$tt\u id
),因为分类法是已知的


我不确定,但是在
创建的{taxonomy}
钩子(注意'd')中调用您的函数可能会更安全一些,该钩子是在调用函数之后调用的(尽管它是一个新条目,这可能不会有什么区别)。

如果我理解正确,您必须根据
$term\u id
参数检索术语的详细信息。比如:

function custom_create_packages( $term_id, $tt_id, $taxonomy ){

    if($taxonomy == 'package_type'){
        $term = get_term( $term_id, $taxonomy );
        $new_page_title = $term->name;
我不知道代码中的分类法slug(“包类型”)是否只是一个示例,但它不应该包含空格(请参阅)

可能值得将您的操作从
create_term
更改为
create_{taxonomy}
(例如
create_package_type
),以消除检查分类法的需要。请注意,
create{taxonomy}
只有两个参数(
$term\u id
$tt\u id
),因为分类法是已知的

我不确定,但是在
创建的{taxonomy}
钩子(注意'd')中调用您的函数可能更安全,它是在调用函数之后调用的(尽管它是一个新条目,这可能不会有什么区别)