Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to display some taxonomies directly in "Posts" label, as standard post, not in a separate label like "Books" for exp., but i don't know how. Is there a way to do this? This is the code:

class PostTypes {

var $types = array();
var $taxonomy = array();

function __construct($types = array(), $taxonomy = array()){
    $this->types = $types + $this->types;
    $this->taxonomy = $taxonomy + $this->taxonomy;
    $this->init();
}

function init(){
    add_action( 'init', array(&$this, 'register_post_type',) );
    add_action( 'init', array(&$this, 'register_taxonomy',) );
}


function register_post_type(){
    global $options;

    foreach ($this->types as $k => $v){
        $vowels = array('a', 'e', 'i', 'o', 'u');
        $a = 'a';
        $slug = $v['slug'];
        $name = $v['name'];

        $plural = $name.'s';
        $menu_name = $plural;
        if(isset($v['menu-name']))
            $menu_name = $v['menu-name'];

        $labels = array(
            'name'                  => __( $plural, 'post type general name' ),  
            'singular_name'         => __( $name, 'post type singular name' ),  
            'add_new'               => __( 'Add New', strtolower( $name ) ),  
            'add_new_item'          => __( 'Add New ' . $name ),  
            'edit_item'             => __( 'Edit ' . $name ),  
            'new_item'              => __( 'New ' . $name ),  
            'all_items'             => __( 'All ' . $plural ),  
            'view_item'             => __( 'View ' . $name ),  
            'search_items'          => __( 'Search ' . $plural ),  
            'not_found'             => __( 'No ' . strtolower( $plural ) . ' found'),  
            'not_found_in_trash'    => __( 'No ' . strtolower( $plural ) . ' found in Trash'),  
            'parent_item_colon'     => '',  
            'menu_name'             => $menu_name

        );


        $supports = array('title','editor','thumbnail', 'comments');

        if(isset($v['supports'])){
            $supports = $v['supports'];
        }

        $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'query_var' => false,
            'rewrite' => array('slug' => $slug),
            'capability_type' => 'post',
            'has_archive' => false,
            'hierarchical' => false,
            'menu_position' => 5,
            'taxonomies' => array(),
            'supports' => $supports
        );
        register_post_type($k, $args);


    }
}


function register_taxonomy(){

    foreach ($this->taxonomy as $k => $v){

        $taxonomy_slug =  $v['slug'];

        $name = $v['name'];
        $plural = $name.'s';
        $types = $v['post-types'];


        $labels = array(
            'name' => __( $name, 'taxonomy general name' ),
            'singular_name' => __( $name, 'taxonomy singular name' ),
            'search_items'          => __( 'Search ' . $name ), 
            'popular_items' => __( 'Popular '.$name ),
            'all_items' => __( 'All '.$name ),
            'parent_item' => null,
            'parent_item_colon' => null,
            'edit_item' => __( 'Edit '.$name ), 
            'update_item' => __( 'Update '.$name ),
            'add_new_item' => __( 'Add New '.$name ),
            'new_item_name' => __( 'New '.$name.' Name' ),
            'separate_items_with_commas' => __( 'Separate '.$name.' with commas' ),
            'add_or_remove_items' => __( 'Add or remove '.$name ),
            'choose_from_most_used' => __( 'Choose from the most used '.$name ),
            'menu_name' => __( $name ),
        );  

        if($v['type'] == 'category'){

            register_taxonomy($k, $types, array(
                'hierarchical' => true,
                'labels' => $labels,
                'show_ui' => true,
                'query_var' => true,
                'rewrite' => array( 'slug' => $taxonomy_slug, 'with_front' => false),
            ));

        }elseif($v['type'] == 'tags'){
            register_taxonomy($k, $types, array(
                'hierarchical' => false,
                'labels' => $labels,
                'show_ui' => true,
                'update_count_callback' => '_update_post_term_count',
                'query_var' => true,
                'rewrite' => array( 'slug' => $taxonomy_slug, 'with_front' => false),
            ));


        }   

    }


}

}

share|improve this question
    
same question as in my other comment- what are trying to get to appear under the Posts menu? your second code block creates a books post type and adds the default category taxonomy to books. you're not doing anything with posts here. –  Milo Jan 28 '13 at 20:45
    
Yes, Milo, under the Posts menu. –  Blanka Jan 28 '13 at 20:46
    
WHAT under the posts menu??? –  Milo Jan 28 '13 at 20:51
    
What I'm trying to do, is to display this post type and taxonomy (BOOKS) - which is already registered - directly in standard post ( under the Posts menu ), not in a separately label, and to be compatible with standard WP posts. –  Blanka Jan 28 '13 at 21:07
add comment

1 Answer 1

when you register a taxonomy, the second argument is the post type it is available for:

register_taxonomy( $taxonomy, $object_type, $args );

if you want the taxonomy to work for a custom type as well as standard posts, you can pass an array of types:

$object_type = array( 'your_custom_type', 'post' );

alternately, you can use register_taxonomy_for_object_type:

register_taxonomy_for_object_type( 'your_custom_taxonomy', 'post' );
share|improve this answer
    
Milo, can you be more specific, please? I can't figure out how to apply what you say in this code. –  Blanka Jan 18 '13 at 19:43
    
Can somebody tell me, please, how to make it work? I struggle for a few days to find a solution, but nothing. What must be change it or add it this code to work? –  Blanka Jan 28 '13 at 17:17
    
I suggest using register_taxonomy_for_object_type in your theme on the init action. modifying the code you posted is not a simple addition. –  Milo Jan 28 '13 at 17:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.