Hi I would like to use category-(slug).php for my custom post type.
In functions.php I have defined the movies post type as following
add_action( 'init', 'create_post_type_movie' );
function create_post_type_movie() {
register_post_type( 'ra_movie',
array(
'labels' => array(
'name' => __( 'Movies' ),
'singular_name' => __( 'Movie' )
),
'public' => true,
'has_archive' =>true,
'rewrite' => array('slug' => 'movie'),
'supports' => array('title','editor','author','thumbnail','excerpt','comments','custom-fields','revisions'),
'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
));
}
So the slug of teh post type is movie. when I load
../category-movie/design
it displays the 404. I am using wordpress 3.5.1 so it should be able to display category-(slug).php
Any ideas?
Thank you
Related
The problem is that only on the edit page of custom post type it shows the taxonomy from Post type and not taxonomy associated with this post type. It correctly shows at Quick Edit post block:
But it doesn't show correctly on the edit page, it shows the taxonomy of the post:
The code which I'm using:
add_action( 'init', function() {
register_taxonomy( 'categories', array( 'blog' ), [
'labels' => [
'name' => 'Blog Categories',
'singular_name' => 'Blog Category',
],
'public' => true,
'hierarchical' => true,
'show_in_rest' => true,
'show_admin_column' => true,
] );
register_post_type( 'blog', array(
'labels' => array(
'name' => 'Blog posts',
'singular_name' => 'Blog post'
),
'public' => true,
'has_archive' => true,
'show_in_rest' => true,
'supports' => array('title','editor', 'thumbnail', 'author'),
'taxonomies' => array( 'categories' ),
) );
} );
I can't figure out where the glitch is and why the taxonomy works fine, but doesn't show up on the edit page.
I updated the friendly URL and it didn't help.
You have to 1st user register_post_type method and after that use register_taxonomy() . May be it work
I have a custom taxonomy 'categories' assigned to a custom post type 'food'. I've created a template 'taxonomy-categories.php'. If I set the permalinks to 'simple', the archive of my taxonomy is working. But if I set the permalinks to 'postname', wordpress throws a 404 error. As an example, mydomain.com/food/summer/ doesn't work, but mydomain.com/?categories=summer is working and shows the content from taxonomy-categories.php.
Here's my code:
add_action('init', 'post_type_food');
function post_type_food() {
register_post_type('food',
array(
'labels' => array(
'name' => 'Rezepte',
'singular_name' => 'Rezept'
),
'public' => true,
'supports' => array('title', 'editor', 'thumbnail'),
'has_archive' => true
)
);
register_taxonomy( 'categories', array('food'), array(
'hierarchical' => true,
'label' => 'Categories',
'singular_label' => 'Category',
'rewrite' => array( 'slug' => 'food', 'with_front'=> false )
)
);
}
Any ideas? Thanks in advance!
I have created a Custom Post Type called user-story. The $args looks like this:
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'description',
'taxonomies' => array('category', 'story-type', 'genre'),
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'http://webmaster.webmastersuccess.netdna-cdn.com/wp-content/uploads/2015/03/pencil.png',
'public' => true,
'has_archive' => true,
'query_var' => true,
'capability_type' => 'post',
'supports' => $supports,
'rewrite' => $rewrite,
'register_meta_box_cb' => 'add_story_metaboxes' );
register_post_type('user_story', $args);
The problem is in line 'taxonomies' => array('category', 'story-type', 'genre'),. I cannot see my taxonomies story-type and genre in Add New Story page in admin. Only category is showing up.
Both story-type and genre are custom taxonomies. I deactivated CPT plugin (user_story) and then reactivated it. But still above custom taxonomies are not coming up.
Both custom taxonomies are registered through plugins and they are visible in Admin menu. Terms registered under these taxonomies are also showing up in their respective list pages.
Screenshot-1: List of terms registered in taxonomy story-type
Screenshot-2: List of terms registered in taxonomy genre
Screenshot-3: Add New Story page - none of the above taxonomies other than only the built-in taxonomy category is listed
I referenced this.
This one should help:
https://developer.wordpress.org/reference/functions/register_taxonomy/
Place this code in your functions.php file and custom taxonomies should be added to your custom post type.
<?php
add_action( 'init', 'create_user_story_tax' );
function create_user_story_tax() {
/* Create Genre Taxonomy */
$args = array(
'label' => __( 'Genre' ),
'rewrite' => array( 'slug' => 'genre' ),
'hierarchical' => true,
);
register_taxonomy( 'genre', 'user-story', $args );
/* Create Story Type Taxonomy */
$args = array(
'label' => __( 'Story Type' ),
'rewrite' => array( 'slug' => 'story-type' ),
'hierarchical' => true,
);
register_taxonomy( 'story-type', 'user-story', $args );
}
?>
I have several custom Post Types in my template. Now i want to build the menu but they are not appearing.
Here I am initialising a custom Post type:
add_action( 'init', 'create_subpage_type' );
function create_subpage_type() {
register_post_type( 'subpage',
array(
'show_in_nav_menus' => true,
'labels' => array(
'name' => __( 'Disziplinen' ),
'singular_name' => __( 'Disziplin' )
),
'public' => true,
'supports' => array( 'title'),
'rewrite' => array('slug' => 'behandlungen'),
)
);
}
I think in this view should now 'disziplin' appear, shouldn't it?
Thanks for your help.
Cheers
Try clicking on "screen options" in the top / right. Sometimes the boxes are hidden by default.
See this bug, since you are declaring the post type public as true, there is no need to redeclare show_in_nav_menus
Try this:
add_action( 'init', 'create_subpage_type' );
function create_subpage_type() {
$labels = array(
'name' => __( 'Disziplinen' ),
'singular_name' => __( 'Disziplin' )
);
$args = array(
'labels' => $labels,
'public' => true,
'supports' => array( 'title'),
'rewrite' => array('slug' => 'behandlungen')
);
register_post_type( 'subpage', $args);
}
I've created a custom post type and I'm trying to use a custom template for showing the content.
My template file is named single-event.php <-- The error was here
My custom post type code is:
function create_post_type() {
$args = array(
'labels' => array(
'name' => __( 'Événement' ),
'singular_name' => __( 'Événement' ),
'add_new' => __('Nouvel Événement')
),
'public' => true,
'has_archive' => true,
'taxonomies' => array('event_data'),
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
'rewrite' => array('slug' => 'event')
);
register_post_type( 'event',$args);
}
My custom template looks like this:
<?php get_header(); ?>
<div id="event" class="full-width-container single-post">
TEEEEEEEST
</div>
<?php get_footer(); ?>
Opening a custom post in my browser, the url is:
http://my.site.no/?event=my-custom-post-title
But why is it using single.php and not single-event.php? What am I missing?
I finally found my mistake - two actually.
I had a category called event - that was my first mistake (I think).
My second mistake was that my filename was singe-event.php <-- missing the l
And that's how you spend 5 hours debugging and reading up on Custom Templates combined with Custom Post Types....
Wordpress need sometimes refresh permalink with custom posts.
You should try to activate permalink and try again !
Hope it will work for you..
And just add rewrite parameter and try url example.com/event
function create_post_type() {
$args = array(
'labels' => array(
'name' => __( 'Événement' ),
'singular_name' => __( 'Événement' ),
'add_new' => __('Nouvel Événement')
),
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'event' ), //Add this parameter
'taxonomies' => array('event_data'),
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
'rewrite' => array('slug' => 'event')
);