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.

The actual post type support categories and I want to add also support for tags.

I have this code:

register_taxonomy(
    'category_' . $slug,
    array( $slug ), 
    array(
        'hierarchical' => true,
        'label' => "$slug Categories",
        'singular_label' => "$slug Category",
        'rewrite' => true
    )
);

So, I was trying to duplicate this for supporting tags but is not working.

This is the entire code for portfolio post type :

$portfolio_slugs = get_option("zeitgeist_portfolio_slug");
if(is_array($portfolio_slugs))
    foreach ( $portfolio_slugs as $slug ){
        add_action('init', 'create_portfolio');
        register_taxonomy("category_".$slug, array($slug), 
        array("hierarchical" => true, "label" => "$slug Categories", "singular_label" => "$slug Category", "rewrite" => true));
        register_taxonomy("tags_".$slug, array($slug), array("hierarchical" => false, "label" => "$slug Tags", "singular_label" => "$slug Tags", "rewrite" => true));



function create_portfolio() {
    $portfolio_slugs = get_option("zeitgeist_portfolio_slug");
    $portfolio_counter = 0;
    $portfolio_names = get_option("zeitgeist_portfolio_name");
    foreach ( $portfolio_slugs as $slug ){
        $portfolio_args = array(
            'label' => __("Portfolio '".$portfolio_names[$portfolio_counter]."'"),
            'singular_label' => __($portfolio_names[$portfolio_counter++]),
            'public' => true,
            'show_ui' => true,
            'capability_type' => 'post',
            'hierarchical' => false,
            'rewrite' => array('slug' => $slug, 'with_front' => true),
            'supports' => array('title', 'editor', 'thumbnail', 'author', 'comments', 'excerpt')
        );
        register_post_type($slug,$portfolio_args);
    }
}

function portfolioSingleRedirect(){
    global $wp_query;
    $queryptype = $wp_query->query_vars["post_type"];
    $portfolio_slugs = get_option("zeitgeist_portfolio_slug");
    if(is_array($portfolio_slugs))
        foreach ( $portfolio_slugs as $slug ){
            if ($queryptype == $slug){
                if (have_posts()){
                    global $pcat;
                    $pcat = "category_".$slug;
                    require(TEMPLATEPATH . '/single_portfolio.php');
                    die();
                }else{
                    $wp_query->is_404 = true;
                }
            }
        }
}
add_action("template_redirect", 'portfolioSingleRedirect');
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

The categories your code creates is a custom taxonomy, not the default post category taxonomy.

Anyway, if you want to add support for the default post tags taxonomy, the name is post_tag and can be added via the taxonomies argument in your $portfolio_args:

$portfolio_args = array(
    'taxonomies' => array( 'post_tag' ),
    // all of your other portfolio args
);

See register_post_type in Codex for more info.

share|improve this answer
    
Actually I need a custom taxonomy tag exactly like the categories taxonomy in my code –  Alecs Jan 18 '13 at 22:06
    
in register_taxonomy arguments change 'hierarchical' => true to 'hierarchical' => false to make them behave like the default tags taxonomy. –  Milo Jan 18 '13 at 22:09
    
I've tried to register a new taxonomy like categories but with hierarchical - false but is still not working. Or if you can make an edit of my code maybe I miss something. –  Alecs Jan 18 '13 at 22:32
    
what's not working exactly? you've created a taxonomy and it's not hierarchical? if your problems are simply php errors, I suggest enabling debugging and working through them line by line. –  Milo Jan 18 '13 at 23:02
    
I've duplicated the register_taxonomy it was used for creating the categories but with hierarchical - false and I recieve : Parse error: syntax error, unexpected $end on line 52 which is the last line in my code –  Alecs Jan 19 '13 at 16:17
show 3 more comments

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.