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 set up 2 custom post types: beats and tracks. And I set up the taxonomy 'tags' and 'style' for both custom post types.

the permalinks for the custom post types are set in functions.php: beats/%style%/%postname% and tracks/%style%/%postname%

I have a problem, when the url is /beats/%style% and /tracks/%style% without the postname (archive). Then, all 'beats' and 'tracks' posts whiches are in the %style%, are visible. Not only the beats or only the tracks from the style tax.

When I make an echo of get_post_type(), the echo always is 'beats'. Even when the url is /tracks/%style%.

Here is my code:

<?php

add_action('init', 'reg_music');

function reg_music() {
    register_taxonomy(
    'style',
    array (
    0 => 'beats',
    1 => 'tracks',
    ),
    array(
        'label' => 'Styles',
        'singular_label' => 'Style',
        'hierarchical' => true,
        'query_var' => true,
        'rewrite' => array('slug' => 'beats','slug' => 'tracks'),
    )
);

$labels = array(
    'name' => _x('Beats', 'post type general name'),
    'singular_name' => _x('Beat', 'post type singular name')
);

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => 'beats',
    'capability_type' => 'post',
    'hierarchical' => true,
    'menu_position' => null,
    'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes',),
    'rewrite' => array(
        'slug' => 'beats/%style%',
        'with_front' => false
    ),
    'has_archive' => true
); 

register_post_type( 'beats' , $args );

 $labels = array(
    'name' => _x('Tracks', 'post type general name'),
    'singular_name' => _x('Track', 'post type singular name')
);

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => 'tracks',
    'capability_type' => 'post',
    'hierarchical' => true,
    'menu_position' => null,
    'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes',),
    'rewrite' => array(
        'slug' => 'tracks/%style%',
        'with_front' => false
    ),
    'has_archive' => true
); 

  register_post_type( 'tracks' , $args );
  // flush_rewrite_rules();
}

add_filter('post_type_link', 'music_permalink_structure', 10, 4);
function music_permalink_structure($post_link, $post, $leavename, $sample)
{
if ( false !== strpos( $post_link, '%style%' ) ) {
    $event_type_term = get_the_terms( $post->ID, 'style' );
    $post_link = str_replace( '%style%', array_pop( $event_type_term )->slug,         $post_link );
}
return $post_link;
}

register_taxonomy('tags',array (
0 => 'beats',
1 => 'tracks',
),array( 'hierarchical' => false, 'label' => 'Tags','show_ui' => true,'query_var' =>     true,'rewrite' => array('slug' => 'tag'),'singular_label' => 'Tag') );

?>
share|improve this question
add comment

1 Answer

I know you problably won't want to be using yet ANOTHER plugin, but can I make a suggestion to use a highly configurable plugin which handles custom fields / groups, custom post types, and custom taxonomies?

Really great, simple, and easy to use plugin. No hardcore advertising. Doesn't bog down your wordpress website. This plugin is also developed and updated actively.

Download Types - Custom Fields and Custom Post Types Management

I use this plugin on almost every wordpress install. Should be fantastic for what you're trying to do.

Note: this plugin was also reviewed by Joost de Valk, on the Yoast website.

share|improve this answer
    
thx. but I dont know how to make the permalinks like /posttype/taxonomy/posttitle with this plugin. can you help me? –  chrispo May 18 '12 at 15:11
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.