wordpress add individual genre archive - php

I am new to wordpress, and was wanting to know how I would add 22 individual genre types &/or archives to wordpress, as I am coding a movie website.
Also I have added a custom post type 'movies' and want to add the 22 genres as 22 tick boxes to the UI.
Thanks in advance
Steven

You should use register_taxonomy. But I don't think that you should register 22 deifferent categories. You can register one ( genre ) for example and add those 22 different genres. If can register as much as you want new categories/taxonomies. Once registered that taxonomy in edit movie page is right sidebar you will find your genres.
Here is the code:
register_taxonomy(
'genre', # Taxonomy name
array( 'movies' ), # Post Types
array( # Arguments
'labels' => array(
'name' => __( 'Genres', 'crb' ),
'singular_name' => __( 'Genre', 'crb' ),
'search_items' => __( 'Search Genres', 'crb' ),
'all_items' => __( 'All Genres', 'crb' ),
'parent_item' => __( 'Parent Genre', 'crb' ),
'parent_item_colon' => __( 'Parent Genre:', 'crb' ),
'view_item' => __( 'View Genre', 'crb' ),
'edit_item' => __( 'Edit Genre', 'crb' ),
'update_item' => __( 'Update Genre', 'crb' ),
'add_new_item' => __( 'Add New Genre', 'crb' ),
'new_item_name' => __( 'New Genre Name', 'crb' ),
'menu_name' => __( 'Genres', 'crb' ),
),
'hierarchical' => true,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' ),
)
);

Related

wordpress custom post type archive returns no posts

I am trying to get posts related to custom taxonomy.
I have a new CPT called article.
I have two custom taxonomies related to the CPT:tags and cats
I can see the cpt items in a custom archive page called archive-article.php.
the problem is this, I created two new files: taxonomy-cats.php and 'taxonomy-tags.php' the content of this files are exacley as the archive-article.php. file.
I get a massage that nothing was found. I checked and I know that there are custom posts related to this taxonomy value.
This is the url I receive the empty archive:
'http://localhost/broker/cats/sales/'
What can be the problem?
Thank you!
This is the taxonomy code:
function create_cats_taxonomy() {
$labels = array(
'name' => _x( 'cats', 'taxonomy general name' ),
'singular_name' => _x( 'cat', 'taxonomy singular name' ),
'search_items' => __( 'search items' ),
'all_items' => __( 'all items' ),
'parent_item' => __( 'parent item' ),
'parent_item_colon' => __( 'parent item colon:' ),
'edit_item' => __( 'edit item' ),
'update_item' => __( 'update item' ),
'add_new_item' => __( 'add new item' ),
'new_item_name' => __( 'new cat' ),
'menu_name' => __( 'cat'),
);
// Now register the taxonomy
register_taxonomy('cats',array('article'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'cats' ),
));
}
add_action( 'init', 'create_cats_taxonomy' );

How to separate custom post type categories to post categories

I'm trying to separate the category lists for a specific post type "announcement" from the post categories.
I want my announcement post type to have its own category list and not mix with the post category list
Here's my code
function announcement_post_types() {
register_post_type(
'announcement',
array(
'labels' => array(
'name' => __( 'Announcements' ),
'singular_name' => __( 'announcement' ),
'menu_name' => __( 'Announcements' ),
'all_items' => __( 'All Announcements' ),
'view_item' => __( 'View Announcement' ),
'add_new_item' => __( 'New Announcement' ),
'add_new' => __( 'New Announcement' ),
'edit_item' => __( 'Edit Announcements' ),
'update_item' => __( 'Update' ),
'search_items' => __( 'Search' ),
'not_found' => __( 'Not Found' ),
'not_found_in_trash' => __( 'Not Found in Trash' ),
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => 'announcement'),
'menu_icon' => 'dashicons-admin-page',
'supports' => array('title', 'editor', 'custom-fields')
)
);
register_taxonomy(
'announcement_type',
'announcement', // this is the custom post type(s) I want to use this taxonomy for
array(
'hierarchical' => false,
'label' => 'News Types',
'query_var' => true,
'rewrite' => true
)
);
register_taxonomy_for_object_type('category', 'announcement');
}
add_action('init', 'announcement_post_types');
If this code is working, this is what links the regular categories to the announcement post type:
register_taxonomy_for_object_type('category', 'announcement');
We need to exchange it with the new taxonomy you created and registered, so exchange it with this:
register_taxonomy_for_object_type('announcement_type', 'announcement');
Let me know if this did the trick for you, there might be more issues here, but this might also be enough.
UPDATE:
I removed the register_taxonomy_for_object_type('category', 'announcement'); and changed into this
$labels = array(
'name' => _x( 'Categories', 'taxonomy general name' ),
'singular_name' =>_x( 'Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'popular_items' => __( 'Popular Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Announcement Category' ),
'update_item' => __( 'Update Announcement Category' ),
'add_new_item' => __( 'Add New Announcement Category' ),
'new_item_name' => __( 'New Announcement Category' ),
'separate_items_with_commas' => __( 'Separate categories with commas' ),
'add_or_remove_items' => __( 'Add or remove Announcement categories' ),
'choose_from_most_used' => __( 'Choose from the most used categories' )
);
register_taxonomy(
'announcement_type',
'announcement', // this is the custom post type(s) I want to use this taxonomy for
array(
'hierarchical' => false,
'label' => 'News Types',
'query_var' => true,
'label' => __('Announcement Category'),
'labels' => $labels,
'hierarchical' => true,
'show_ui' => true,
'rewrite' => true
)
);
It works for me now,
If you have better answer for this please share :) I want to make this code shorter.

How to duplicate the category submenu in admin panel of wordpress

How to create a second category menu like Seminars >> seminars >> create new seminars >> seminar categories and then I want to duplicate seminar categories and make it Seminar venues with inside remaining the same.
See attached screenshot:
As per my understanding, you just want to create a new taxonomy under Seminars. If you make changes in theme files you can edit the function.php and add the following code
$labels = array(
'name' => _x( 'Seminar Venue', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Venue', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Venue', 'textdomain' ),
'all_items' => __( 'All Venues', 'textdomain' ),
'parent_item' => __( 'Parent Venue', 'textdomain' ),
'parent_item_colon' => __( 'Parent Venue:', 'textdomain' ),
'edit_item' => __( 'Edit Venue', 'textdomain' ),
'update_item' => __( 'Update Venue', 'textdomain' ),
'add_new_item' => __( 'Add New Venue', 'textdomain' ),
'new_item_name' => __( 'New VenueName', 'textdomain' ),
'menu_name' => __( 'Venue', 'textdomain' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' ),
);
register_taxonomy( 'genre', array( 'seminars' ), $args );
Or you can use the plugin Custom Post Type UI. In this plugin go to taxonomy and add a new taxonomy under your post type "seminars"

WordPress || Custom post types, permalinks & numbers

This is for a cat shelter. I have a custom post type, called "cat".
I then have a taxonomy for availability, with "available" and "homed".
Everything works fine... until there are duplicate names of cats. For example, if Milo comes in one month, then a year later, another Milo comes in. Obviously, WordPress will create siteurl/cat/milo/, and then for the second, create siteurl/cat/milo-2/.
Original Milo works fine... as soon as the number is put in, milo-2 doesn't work, and redirects to a 404.
Custom Post Type
function cat_post_type() {
$labels = array(
'name' => _x( 'Cats', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Cat', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Cats', 'text_domain' ),
'name_admin_bar' => __( 'Cats', 'text_domain' ),
'parent_item_colon' => __( 'Parent Cat:', 'text_domain' ),
'all_items' => __( 'All Cats', 'text_domain' ),
'add_new_item' => __( 'Add Cat', 'text_domain' ),
'add_new' => __( 'New Cat', 'text_domain' ),
'new_item' => __( 'New Cat', 'text_domain' ),
'edit_item' => __( 'Edit Cat', 'text_domain' ),
'update_item' => __( 'Update Cat', 'text_domain' ),
'view_item' => __( 'View Cat', 'text_domain' ),
'search_items' => __( 'Search cats', 'text_domain' ),
'not_found' => __( 'No cats found', 'text_domain' ),
'not_found_in_trash' => __( 'No cats found in Trash', 'text_domain' ),
);
$args = array(
'label' => __( 'cats', 'text_domain' ),
'description' => __( 'All cats', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'comments'),
'taxonomies' => array( 'available', 'homed' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-smiley',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'cat', $args );
}
Taxonomy
// Hook into the 'init' action
add_action( 'init', 'cat_post_type', 0 );
function add_custom_taxonomies() {
// Add new "Locations" taxonomy to Posts
register_taxonomy('availability', 'cat', array(
// Hierarchical taxonomy (like categories)
'hierarchical' => true,
// This array of options controls the labels displayed in the WordPress Admin UI
'labels' => array(
'name' => _x( 'Cats Availability', 'taxonomy general name' ),
'singular_name' => _x( 'Cat Availability', 'taxonomy singular name' ),
'search_items' => __( 'Search Cat Availability' ),
'all_items' => __( 'All Availability' ),
'parent_item' => __( 'Parent Availability' ),
'parent_item_colon' => __( 'Parent Availability:' ),
'edit_item' => __( 'Edit Availability' ),
'update_item' => __( 'Update Availability' ),
'add_new_item' => __( 'Add New Availability' ),
'new_item_name' => __( 'New Availability' ),
'menu_name' => __( 'Availability' ),
),
// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'cats', // This controls the base slug that will display before each term
'with_front' => false, // Don't display the category base before "/locations/"
'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
),
));
}
add_action( 'init', 'add_custom_taxonomies', 0 );
We thought it might be something in the DB conflicting... tried re-saving permalinks, removing unused DB entries, disabling all plugins... nothing.
Manually renaming the cat to, say, milo_ works fine, but with any number in it just sends back my 404.
Using Starkers responsive theme, no child theme. Standard htaccess.
Am I missing something blatantly obvious?
Unfinished site here - find a cat with a number in its link... http://catsnottingham.zellement.com/cats/homed/
I have fixed this - I think it must have been a database conflict, corruption or error, so I started again with a fresh WordPress install, which has fixed the issue.
Part of me thinks using "cat" as a CPT may have conflicted with categories... somehow.

Custom taxonomy with hierarchical url link structure

I created a custom taxonomy called instrument_categories. It works fine but I want the link structure to be like this:
www.example.com/instruments/term/subterm
Instead, I get this:
www.example.com/instruments/term/
www.example.com/instruments/subterm
I've read a dozen posts about this, and I can't find anything wrong with my code:
add_action( 'init', 'create_instrument_taxonomies', 0 );
function create_instrument_taxonomies()
{
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Instrument Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Instrument Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Instrument Categories' ),
'popular_items' => __( 'Popular Instrument Categories' ),
'all_items' => __( 'All Instrument Categories' ),
'parent_item' => __( 'Parent Instrument Category' ),
'parent_item_colon' => __( 'Parent Instrument Category:' ),
'edit_item' => __( 'Edit Instrument Category' ),
'update_item' => __( 'Update Instrument Category' ),
'add_new_item' => __( 'Add New Instrument Category' ),
'new_item_name' => __( 'New Instrument Category Name' ),
);
register_taxonomy('instrument_categories',array('sdp_instrument'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'instruments', 'hierarchal' => true, 'with_front' => true ),
));
}
Am I missing something? I've made sure to refresh the permalinks. Why won't this work?
You're really doing it wrong.
Everything you need to know is here : http://thereforei.am/2011/10/28/advanced-taxonomy-queries-with-pretty-urls/

Categories