为自定义帖子类型更改wordpress sql数据库


Change wordpress sql database for custom post types

我想将自定义帖子类型的默认数据库从wp_posts更改为wp_anything_else,我需要有只有特定帖子才能使用的唯一ID。例如,如果我有一个帖子类型的博客,它也会把它添加到wp_posts中,而我不想这样,它会把一切都搞砸:(在functions.php或任何插件中创建自定义帖子类型时,有没有办法更改数据库?

*函数代码.pp

add_filter('body_class','bp_conditional_ie_classes');
/*custom post types*/
add_action('init', 'blogs_register');
 
function blogs_register() {
 
    $labels = array(
        'name' => _x('My Blog', 'post type general name'),
        'singular_name' => _x('Blog Item', 'post type singular name'),
        'add_new' => _x('Add New', 'Blog item'),
        'add_new_item' => __('Add New Blog Item'),
        'edit_item' => __('Edit Blog Item'),
        'new_item' => __('New Blog Item'),
        'view_item' => __('View Blog Item'),
        'search_items' => __('Search Blog'),
        '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' => get_stylesheet_directory_uri() . '/admin.png',
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','thumbnail')
      ); 
 
    register_post_type( 'blogs' , $args );
}

**这个片段不起作用,但这是它允许我添加代码而不干扰它的唯一方法

WordPress帖子(帖子、页面、自定义帖子…)旨在代表您网站的一个实体。由于这种抽象,WordPress对其所有内容类型都使用一个表,因此在平均的站点请求过程中,WP必须只在一个表中查找请求的站点。

在多个表中有多个post类型需要在WP的内核中有不同的查找行为。这就是为什么你想做的事情很复杂。

尽管我确信"博客项目"不需要单独的DB表,但我在wp_posts表中看到的问题是,它们不能在条目之间启用m:n关系。对于这样的用例,您可以考虑使用自定义帖子和自定义分类法的组合。

编辑:当然,你可以编写或使用(如果有的话)一个插件,它可以处理管理和维护额外表所需的所有内容。但这可能永远不会集成到WordPress以及自定义帖子类型中。