Woocommerce taxonomy - wordpress

i made custom taxonomy for woocomerce products, products will be books and ecery book have his own writter.
<pre>function custom_taxonomy_writter() {
$labels = array(
'name' => 'Writters',
'singular_name' => 'Writter',
'menu_name' => 'Writter',
'all_items' => 'All writters',
'parent_item' => 'Parent writter',
'parent_item_colon' => 'Parent writter:',
'new_item_name' => 'New writter name',
'add_new_item' => 'Add new writter',
'edit_item' => 'Edit writter',
'update_item' => 'Update writter',
'separate_items_with_commas' => 'Separate writter with commas',
'search_items' => 'Search writters',
'add_or_remove_items' => 'Add or remove writters',
'choose_from_most_used' => 'Choose from the most used writters',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy('writter', 'product', $args);
}
add_action('init', 'custom_taxonomy_writter', 0);</pre>
Screenshoot from wp admin:
Now I need to display it for example under the product title, and needs to bi link, like tags or categories.

Wooola!
<?php echo get_the_term_list( $post->ID, 'writter', '', ', ' ); ?>
Simple and works!!! And is also linked to author with listing of his books :)

Related

Single page for custom post type with custom taxomies desn't work

I created custom post type "testimonials" with custom taxomies
it works well except of sinbgle page, when I click on permalink it shows "not found".
Here is my code for custom post types/taxonomies:
function testimonials_custom_post_type()
{
$labels = array(
'name' => _x('Testimonials', 'Post type general name'),
'singular_name' => _x('Testimonial', 'Post type singular name'),
'add_new' => _x('Add new Testimonial', 'Grower'),
'add_new_item' => __('Add new Testimonial'),
'edit_item' => __('Edit Testimonial'),
'new_item' => __('New Testimonial'),
'all_items' => __('All Testimonials'),
'view_item' => __('View Testimonial'),
'search_items' => __('Search Testimonials'),
'not_found' => __('No testimonials found'),
'not_found_in_trash' => __('No testimonials found in Trash'),
'parent_item_colon' => '',
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => false,
'query_var' => false,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'exclude_from_search' => false,
'supports' => array('title', 'editor', 'thumbnail' ),
'menu_position' => 6,
'menu_icon' => 'dashicons-id',
'taxonomies' => array( 'subjects' ),
);
register_post_type('testimonials', $args);
}
add_action('init', 'testimonials_custom_post_type');
/*register custom taxonomies for testimonials*/
add_action( 'init', 'create_testimonials_taxonomies', 0 );
function create_testimonials_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Subjects', 'subjects', 'textdomain' ),
'singular_name' => _x( 'Subject', 'subject', 'textdomain' ),
'search_items' => __( 'Search Subject', 'textdomain' ),
'all_items' => __( 'All Subjects', 'textdomain' ),
'edit_item' => __( 'Edit Subject', 'textdomain' ),
'update_item' => __( 'Update Subject', 'textdomain' ),
'add_new_item' => __( 'Add new Subject', 'textdomain' ),
'new_item_name' => __( 'New Category Subject', 'textdomain' ),
'menu_name' => __( 'Subject', 'textdomain' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => false,
'query_var' => true,
'rewrite' => array( 'slug' => 'subjects' ),
);
register_taxonomy( 'subjects', array( 'testimonials' ), $args );
}
/*register custom taxonomies for testimonials*/
I tried to use flush_rewrite_rules( false ); and tried to update permalinks in wp admin panel it's still not working
For custom post type "testimonials" I created single-testimonials.php in my child theme
Thank you very much for any help!
To fix my bug I had to set 'publicly_queryable' to 'true'
and it works now ))
You could try to create taxonomy-subjects.php and refresh your permalinks after you try each time.

Taxonomy term permalink is not working as expected

I have CPT called forms_cpt and a Taxonomy called forms_tax. In my page-forms.php I am able to crate a list of forms_tax terms like
<ul>
<?php
foreach ($tax_terms as $tax_term) {
echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';
}
?>
</ul>
which is creating a list of terms. but whenever I click on them it landed in a wrong URL. For example if click on soccer term it landed at
http://www.domain.ca/soccer/
instead of
http://www.domain.ca/Forms/soccer/
What am I doing wrong?
function gen_forms_tax() {
$labels = array(
'name' => 'Form Types',
'singular_name' => 'Form Type',
'menu_name' => 'Form Types',
'all_items' => 'All Form Types',
'parent_item' => 'Form Parent',
'parent_item_colon' => 'Form Parents:',
'new_item_name' => 'New Form Name',
'add_new_item' => 'Add New Form',
'edit_item' => 'Edit Form',
'update_item' => 'Update Form',
'separate_items_with_commas' => 'Separate Form with commas',
'search_items' => 'Search Form',
'add_or_remove_items' => 'Add or remove Form',
'choose_from_most_used' => 'Choose from the most used Form',
'not_found' => 'Form Not Found',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'forms_tax', array( 'forms_cpt' ), $args );
}
add_action( 'init', 'gen_forms_tax', 0 );
function gen_forms_cpt() {
$labels = array(
'name' => 'Forms',
'singular_name' => 'Form',
'menu_name' => 'Form',
'name_admin_bar' => 'Form',
'parent_item_colon' => 'Form Parent:',
'all_items' => 'All Forms',
'view_item' => 'View Forms',
'add_new_item' => 'Add New Form',
'add_new' => 'Add New Form',
'new_item' => 'New Form',
'edit_item' => 'Edit Form',
'update_item' => 'Update Form',
'search_items' => 'Search Form',
'not_found' => 'Form Not found',
'not_found_in_trash' => 'Form Not found in Trash',
);
$args = array(
'description' => 'This Post Type Adds Form to Website',
'labels' => $labels,
'supports' => array( 'title', 'excerpt', ),
'taxonomies' => array( 'forms_tax' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'rewrite' => array( 'slug' => 'Forms','with_front' => true, 'hierarchical' => true ),
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'forms_cpt', $args );
}
add_action( 'init', 'gen_forms_cpt', 0 );
Solution : You need to follow the steps given below.
1) Go to Settings from Admin panel.
2) Go to permalinks
3) Save the permalinks
It should work after you save the parmalinks. You always need update the permalinks once you add any rewrite rule to the site.

Include Product category base and %product_cat% in rewrite taxonomy

I would like to have the Product category base and %product_cat% in the new taxonomys i added to woocomerce, any ideas ?
$flavour_labels = array(
'name' => 'Flavours',
'singular_name' => 'Flavour',
'menu_name' => 'Flavour',
'all_items' => 'All Flavours',
'parent_item' => 'Parent Flavour',
'parent_item_colon' => 'Parent Flavour:',
'new_item_name' => 'New Flavour Name',
'add_new_item' => 'Add New Flavour',
'edit_item' => 'Edit Flavour',
'update_item' => 'Update Flavour',
'separate_items_with_commas' => 'Separate Flavour with commas',
'search_items' => 'Search Flavours',
'add_or_remove_items' => 'Add or remove Flavours',
'choose_from_most_used' => 'Choose from the most used Flavours',
);
$flavour_args = array(
'labels' => $flavour_labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'flavour'),
);
register_taxonomy( 'product_flavour', 'product', $flavour_args );
register_taxonomy_for_object_type( 'product_flavour', 'product' );
This is the url i have
http://site.local/flavour/name/
And this is what i want
http://site.local/gear/product_cat/flavour/name/
I dont wanna hard code anything in the rewrite
Make sure your .htaccess file is writable.
In the "category base" write your base string "product_cat" with no percentage signs (%)

insert taxonomy to a custom post type

I have been created a custom post type and create a taxonomy for it, below is the code which i used to create those:
//create custom post type of jobs
add_action( 'init', 'create_jobs' );
function create_jobs() {
register_post_type( 'jobs',
array(
'labels' => array(
'name' => 'jobs',
'singular_name' => 'Jobs',
'add_new' => 'Add New',
'add_new_item' => 'Add New Jobs',
'edit' => 'Edit',
'edit_item' => 'Edit Jobs',
'new_item' => 'New Jobs',
'view' => 'View',
'view_item' => 'View Jobs',
'search_items' => 'Search Jobs',
'not_found' => 'No Jobs found',
'not_found_in_trash' => 'No Jobs found in Trash',
'parent' => 'Parent Jobs'
),
'public' => true,
'menu_position' => 15,
'supports' => array( 'title', 'editor', 'comments', 'thumbnail' ),
'taxonomies' => array( '' ),
'menu_icon' => 'dashicons-visibility',
'has_archive' => true
)
);
}
//create a taxonomy for jobs
add_action( 'init', 'create_jobstax', 0 );
function create_jobstax() {
register_taxonomy(
'jobs_taxonomy_genre',
'jobs',
array(
'labels' => array(
'name' => 'Create Jobs Genre',
'add_new_item' => 'Add New jobs genre',
'new_item_name' => "New jobs genre"
),
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true
)
);
}
now what i want is to insert a default taxonomy for that custom post type only, example: i want to insert "latest" and "active" as a default taxonomy for the jobs custom post type, how to achieve that? currently looking for a approach around but seems found nothing to meet my needs. Any ideas, recommendations and suggestions, would love to hear. Very thank you in advance.
Please try this plugin, you don't need to take headache like this. you will get complete separate module for your post type with category and tag
custom post type maker
1) create a post type "jobs" as per your requirement.
2) then create 2 taxonomy with name like 'Job category' & 'Job tags'.
3) when your creating the taxonomy Please select your job post type which is given at the bottom of taxonomy creation page.
finally you will get the complete separate module with following
Customize this code .
add_action('init','create_custom_posts');
function create_custom_posts(){
register_post_type( 'cms_chooser', array(
'labels' => array(
'name' => 'CMS Chooser',
'singular_name' => 'CMS Chooser',
'add_new' => 'Add New',
'add_new_item' => 'Add New CMS',
'edit_item' => 'Edit',
'edit' => 'CMS',
'new_item' => 'New CMS',
'view_item' => 'View Detail',
'search_items' => 'Search in CMS',
'not_found' => 'No CMS found',
'not_found_in_trash' => 'No Posts found in Trash',
'view' => 'View Post'
),
'public' => true,
//'capability_type' => 'post',
'hierarchical' => true,
'exclude_from_search' => false,
'show_in_nav_menus' => false,
'query_var' => true,
'menu_position' => 5,
'supports' => array('title','page-attributes'),
'has_archive' => true,
'taxonomies' => array('cms-category'),
'rewrite' => array('slug' => 'cms', 'with_front' => false )
)
);
register_taxonomy(
'cms-category',
'cms_chooser',
array(
'labels' => array(
'name' => 'Category',
'singular_name' => 'Category',
'search_items' => 'Search Category',
'popular_items' => 'Popular Category',
'all_items' => 'All Category',
'parent_item' => 'Parent Category',
'parent_item_colon' => 'Parent Category',
'edit_item' => 'Edit Category',
'update_item' => 'Update Category',
'add_new_item' => 'Add New Category',
'new_item_name' => 'New Category Name'
),
'hierarchical' => false,
'show_in_nav_menus' => false,
'exclude_from_search' => true,
'public' => false,
'show_ui' => true,
'query_var' => 'cms-category',
'show_tagcloud' => true,
'rewrite' => true
)
);
}
I would have approached it this way.
Create categories "latest","active","xyz","blah-blah", for this custom-post.
On admin side add js to select the required two categories. (Let me know if you need code for this.)

How to Add Custom Taxonomy To Woocomerce Plugin

I am trying to add a Custom Taxonomy to Woocommerce by targeting the product post type in woocommerce. I used following code and add them into function.php I am not getting any error message but the tax is not showing in the Woocommerce as well.
Can you please let me know how I can do this or what I am doing wrong here?
<?php
// Register Custom Taxonomy
function custom_taxonomy_Item() {
$labels = array(
'name' => 'Items',
'singular_name' => 'Item',
'menu_name' => 'Item',
'all_items' => 'All Items',
'parent_item' => 'Parent Item',
'parent_item_colon' => 'Parent Item:',
'new_item_name' => 'New Item Name',
'add_new_item' => 'Add New Item',
'edit_item' => 'Edit Item',
'update_item' => 'Update Item',
'separate_items_with_commas' => 'Separate Item with commas',
'search_items' => 'Search Items',
'add_or_remove_items' => 'Add or remove Items',
'choose_from_most_used' => 'Choose from the most used Items',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'item', 'product', $args );
}
?>
This php function is not being called, at least in this code. Make sure you are calling your custom_taxonomy_item and hook into init;
add_action( 'init', 'custom_taxonomy_item', 0 );
And place this above/below your code.

Resources