Hello guys,
I've got the problem that i cant handle without your help.
Here's the thing:
I want to create custom posts named Transmisje, and than custom categories for it (taxonomies) - Dyscyplina, and then get:
mydomain.pl/transmisje - archive page with posts from custom posts 'Transmisje'
mydomain.pl/tramsisje/dyscyplina/name-of-custom-category - archive page for custom categories (taxonomies) in Dyscyplina
and the las one, for the single custom post mydomain.pl/dyscyplina/name-of-custom-category/post-name
I was looking for tutorials and Ive made custom posts, and taxonomies, and something that should resolve the permalinks problem but nothing helped.
here is the code:
function my_custom_post_product() {
$labelsProduct = array(
'name' => _x( 'Produkty', 'post type general name' ),
'singular_name' => _x( 'Produkty', 'post type singular name' ),
'add_new' => _x( 'Dodaj nowy produkt', 'book' ),
'add_new_item' => __( 'Dodawanie nowego produktu' ),
'edit_item' => __( 'Edytuj produkt' ),
'new_item' => __( 'Nowy produkt' ),
'all_items' => __( 'Lista produktów' ),
'view_item' => __( 'Zobacz produkt' ),
'search_items' => __( 'Szukaj produktu' ),
'not_found' => __( 'Nie znaleziono produktów' ),
'not_found_in_trash' => __( 'Nie znalezionko produktów w koszu' ),
'parent_item_colon' => '',
'menu_name' => 'Transmisje'
);
$argsProduct = array(
'labels' => $labelsProduct,
'description' => 'Wprowadź nowy produkt.',
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
'has_archive' => true,
'hierarchical' => true,
'rewrite' => array('slug' => 'transmisje/%dyscyplina%','with_front' => false),
'query_var' => true,
//'rewrite' => true,
//'publicly_queryable' => false,
);
register_post_type( 'transmisje', $argsProduct );
}
add_action( 'init', 'my_custom_post_product' );
/* A taxonomies for products (category taxonomy) */
function my_taxonomies_product() {
$labelsTaxProducts = array(
'name' => _x( 'Kategorie', 'taxonomy general name' ),
'singular_name' => _x( 'Kategorie', 'taxonomy singular name' ),
'search_items' => __( 'Wyszukaj kategorie' ),
'all_items' => __( 'Wszystkie kategorie' ),
'parent_item' => __( 'Rodzic kategorii' ),
'parent_item_colon' => __( 'Rodzic produktu:' ),
'edit_item' => __( 'Edytuj kategorie' ),
'update_item' => __( 'Aktualizuj kategorie' ),
'add_new_item' => __( 'Dodaj nową kategorie' ),
'new_item_name' => __( 'Nazwa nowej kategorii' ),
'menu_name' => __( 'Dyscypliny' ),
);
$argsTaxProducts = array(
'labels' => $labelsTaxProducts,
'hierarchical' => true,
'public' => true,
'query_var' => 'dyscyplina',
//slug prodotto deve coincidere con il primo parametro dello slug del Custom Post Type correlato
'rewrite' => array('slug' => 'dyscyplina' ),
'_builtin' => false,
);
register_taxonomy( 'dyscyplina', 'transmisje', $argsTaxProducts );
}
add_action( 'init', 'my_taxonomies_product', 0 );
add_filter('post_link', 'dyscyplina_permalink', 1, 3);
add_filter('post_type_link', 'dyscyplina_permalink', 1, 3);
function category_permalink($permalink, $post_id, $leavename) {
//con %category% catturo il rewrite del Custom Post Type
if (strpos($permalink, '%dyscyplina%') === FALSE) return $permalink;
// Get post
$post = get_post($post_id);
if (!$post) return $permalink;
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'dyscyplina');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
$taxonomy_slug = $terms[0]->slug;
else $taxonomy_slug = 'no-category';
return str_replace('%dyscyplina%', $taxonomy_slug, $permalink);
}
what I have now?
On the home page permalinks are just with my domain
on the mydomain.pl/transmisje/ I have permalinks mydomain.pl/transmisje/
and on the mydomain.pl/dyscyplina/name-of-custom-category/ permalink is "mydomain.pl/dyscyplina/name-of-custom-category/"
It looks that permalink is generating wrong, but I don't know why. I will be very pleased if you could help me guys!
Thanks, Budzan