使用相同的功能创建多个自定义帖子

时间:2017-05-26 09:41:23

标签: wordpress custom-post-type

<_>在__construct()函数中我创建了两个add_action,do_action如下所示:

class eksoptn
{

function _init()
{

    add_action('post_creater', array($this, 'post_register'), 10, 2); 
    do_action('post_creater', 'slideshow', 'HOmeslide hsow'); 
    do_action('post_creater', 'portfolio', 'porfolio'); 
}

 function post_register($post_slug=null, $postname=null) {


    $labels = array(
        'name' => _x($postname, 'post type general name'),
        'singular_name' => _x($postname, 'post type singular name'),
        'add_new' => _x('Add '.$postname, 'snack'),
        'add_new_item' => __('Add '.$postname),
        'edit_item' => __('Edit '.$postname),
        'new_item' => __('New '.$postname),
        'view_item' => __('View '.$postname),
        'search_items' => __('Search '.$postname),
        'not_found' =>  __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'menu_icon' => 'dashicons-admin-generic',
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','thumbnail')
    ); 

    register_post_type( $post_slug , $args );
}
}

 $eksoptn = new eksoptn; 
 $eksoptn->_init();

当我尝试上面的代码然后显示如下错误

Call to a member function add_rewrite_tag() on a non-object in C:\wamp\www\fresenius\wp-includes\rewrite.php

当我在register_function中输入循环时,它工作正常。 但使用do_action显示我的错误 那我该怎么办呢。

0 个答案:

没有答案