Wordpress custom taxonomy move meta_box - wordpress

I have a custom meta box(taxonomy) that is positioned on side of my custom post. I want to move it to normal position, but when I remove it(remove_meta_box), and re-add(add_meta_box) I only get bar, with no options to select anything. I think I didn't write proper $callback, but I tried many variations, and don't have a clue.
function create_isotope_taxonomies()
{
$labels = array(
'name' => _x( 'Select Category', 'taxonomy general name' ),
'singular_name' => _x( 'Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'popular_items' => __( 'Popular Categories' ),
'all_items' => null,
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit' ),
'update_item' => __( 'Update' ),
'add_new_item' => __( 'Add New' ),
'new_item_name' => __( 'New Category' ),
'separate_items_with_commas' => __( 'Separate writers with commas' ),
'add_or_remove_items' => __( 'Add or remove categories' ),
'choose_from_most_used' => __( 'Choose from the most used categories' ),
'menu_name' => __( 'Categories' ),
);
register_taxonomy('fzisotope_categories','fzisotope_post',array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'fzisotope_categories' ),
));
}
function fzisotope_categories_meta_box(){
remove_meta_box('fzisotope_categoriesdiv', 'fzisotope_post', 'side');
add_meta_box( 'fzisotope_categoriesdiv', 'Select Category', 'fzisotope_categories_meta_box', 'fzisotope_post', 'normal', 'high');
//print '<pre>';print_r( $wp_meta_boxes['post'] );print '<pre>';
}
add_action( 'admin_init', 'fzisotope_categories_meta_box', 0 );
Thanks for reading

You have to use:
post_categories_meta_box for taxonomies with hierarchies.
remove_meta_box('fzisotope_categoriesdiv', 'fzisotope_post', 'side');
add_meta_box( 'fzisotope_categoriesdiv', 'XXXXXXXXXXX', 'post_categories_meta_box', 'post', 'normal', 'high', array( 'taxonomy' => 'fzisotope_categories' ));

Related

custom taxonomy meta box doesn't show in the WordPress admin menu

I have created a new custom taxonomy in WordPress functions.php file but when I want to add new post or edit one I cannot found my custom taxonomy meta box in the right side of the admin menu
my functions.php code for custom taxonomy:
function create_business_taxonomy() {
$labels = array(
'name' => _x( 'Businesses', 'taxonomy general name' ),
'singular_name' => _x( 'Business', 'taxonomy singular name' ),
'search_items' => __( 'Search Businesses' ),
'all_items' => __( 'All Businesses' ),
'parent_item' => __( 'Parent Business' ),
'parent_item_colon' => __( 'Parent Business:' ),
'edit_item' => __( 'Edit Business' ),
'update_item' => __( 'Update Business' ),
'add_new_item' => __( 'Add New Business' ),
'new_item_name' => __( 'New Business Name' ),
'menu_name' => __( 'Business' ),
);
register_taxonomy('business-type',array('post'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => false,
'query_var' => true,
'rewrite' => array( 'business-type' => 'topic' ),
));
}
add_action( 'init', 'create_business_taxonomy', 0 );
but I can't find in where I marked in the screenshot:
Did I forget or missed something?
You need to set 'show_in_rest' => true. ( (boolean) (optional) Whether to include the taxonomy in the REST API. You will need to set this to true in order to use the taxonomy in your gutenberg metablock. ). So your code will be like this:
function create_business_taxonomy() {
$labels = array(
'name' => _x( 'Businesses', 'taxonomy general name' ),
'singular_name' => _x( 'Business', 'taxonomy singular name' ),
'search_items' => __( 'Search Businesses' ),
'all_items' => __( 'All Businesses' ),
'parent_item' => __( 'Parent Business' ),
'parent_item_colon' => __( 'Parent Business:' ),
'edit_item' => __( 'Edit Business' ),
'update_item' => __( 'Update Business' ),
'add_new_item' => __( 'Add New Business' ),
'new_item_name' => __( 'New Business Name' ),
'menu_name' => __( 'Business' ),
);
register_taxonomy('business-type',array('post'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => false,
'query_var' => true,
'show_in_rest' => true,
'rewrite' => array( 'business-type' => 'topic' ),
));
}
add_action( 'init', 'create_business_taxonomy', 0 );

How do i add custom tag option in custom wordpress page?

See here is no tags box how can I add a tag box in the right panel please help me.
Tags are just a taxonomy type so you can create a new taxonomy for your page post type:
add_action( 'init', 'create_tags_for_pages_taxonomy', 500, 0);
function create_tags_for_pages_taxonomy() {
$labels = array(
'name' => _x( 'Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Tags' ),
'all_items' => __( 'All Tags' ),
'parent_item' => __( 'Parent Tag' ),
'parent_item_colon' => __( 'Parent Tag:' ),
'edit_item' => __( 'Edit Tag' ),
'update_item' => __( 'Update Tag' ),
'add_new_item' => __( 'Add New Tag' ),
'new_item_name' => __( 'New Tag Name' ),
'menu_name' => __( 'Tags' ),
);
// Now register the taxonomy
register_taxonomy('page_tags',array('release'), array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'topic' ),
));
}

Wordpress CPT multiple categories in the url

I have a CPT Traffi coffice.
Url: www.domain.com/traffic-offices/
When add a new like www.domain.com/traffic-offices/germany/ its ok.
When i add a new post Saksen then it automaticly makes this url www.domain.com/traffic-offices/saksen but i want www.domain.com/traffic-offices/germany/saksen. If i fill that in it automaticly makes www.domain.com/traffic-offices/germany-saksen.
How can i achieve this url www.domain.com/traffic-offices/germany/saksen ?
function trafficoffice_post_type() {
// Labels
$labels = array(
'name' => _x("trafficoffices", "post type general name"),
'singular_name' => _x("trafficoffices", "post type singular name"),
'menu_name' => 'trafficoffices',
'add_new' => _x("Add new", "trafficoffice item"),
'add_new_item' => __("Add new"),
'edit_item' => __("trafficoffice aanpassen"),
'new_item' => __("Add new trafficoffice"),
'view_item' => __("View trafficoffice"),
'search_items' => __("Search Profiles"),
'not_found' => __("No Profiles Found"),
'not_found_in_trash' => __("No Profiles Found in Trash"),
'parent_item_colon' => ''
);
// Register post type
register_post_type('trafficoffice', array(
'labels' => $labels,
'public' => true,
'has_archive' => false,
'rewrite' => array(
'slug' => 'traffic-offices',
),
'supports' => array('title', 'editor', 'thumbnail')
));
}
add_action('init', 'trafficoffice_post_type', 0);
One way of doing that is using taxonomies.
Register a new taxonomy called "country".
Create a new category "Germany" with slug "germany".
Assign the category "Germany" to the post "Saksen".
Here is the code to register the taxonomy:
$labels = array(
'name' => _x( 'Countries', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Country', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Search Countries', 'textdomain' ),
'popular_items' => __( 'Popular Countries', 'textdomain' ),
'all_items' => __( 'All Countries', 'textdomain' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Country', 'textdomain' ),
'update_item' => __( 'Update Country', 'textdomain' ),
'add_new_item' => __( 'Add New Country', 'textdomain' ),
'new_item_name' => __( 'New Country Name', 'textdomain' ),
'separate_items_with_commas' => __( 'Separate Countries with commas', 'textdomain' ),
'add_or_remove_items' => __( 'Add or remove Countries', 'textdomain' ),
'choose_from_most_used' => __( 'Choose from the most used Countries', 'textdomain' ),
'not_found' => __( 'No Countries found.', 'textdomain' ),
'menu_name' => __( 'Countries', 'textdomain' ),
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
//'rewrite' => array( 'slug' => 'country' ),
);
register_taxonomy( 'country', 'trafficoffice', $args );
Make sure the permalink settings of WordPress (Settings -> Permalinks) include the category.
/%category%/%postname%/
Read more about register_taxonomy().

How to customize posts tags meta box

How to customise posts tags meta box and make similar to like post categories meta box with tags parents relation and just same ui as category meta box.
The main difference between the tags and categries is that tag is not hierarchical while categories are. Now to make the tags hierarchichal please paste the below code to your functions.php.
function hierarchical_tags() {
// rewrite functionality of WordPress tags
global $wp_rewrite;
$rewrite = array(
'hierarchical' => false, // Maintains tag permalink structure
'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag',
'with_front' => ! get_option('tag_base') || $wp_rewrite->using_index_permalinks(),
'ep_mask' => EP_TAGS,
);
// tag labels
$labels = array(
'name' => _x( 'Tags', 'Taxonomy General Name', 'hierarchical_tags' ),
'singular_name' => _x( 'Tag', 'Taxonomy Singular Name', 'hierarchical_tags' ),
'menu_name' => __( 'Taxonomy', 'hierarchical_tags' ),
'all_items' => __( 'All Tags', 'hierarchical_tags' ),
'parent_item' => __( 'Parent Tag', 'hierarchical_tags' ),
'parent_item_colon' => __( 'Parent Tag:', 'hierarchical_tags' ),
'new_item_name' => __( 'New Tag Name', 'hierarchical_tags' ),
'add_new_item' => __( 'Add New Tag', 'hierarchical_tags' ),
'edit_item' => __( 'Edit Tag', 'hierarchical_tags' ),
'update_item' => __( 'Update Tag', 'hierarchical_tags' ),
'view_item' => __( 'View Tag', 'hierarchical_tags' ),
'separate_items_with_commas' => __( 'Separate tags with commas', 'hierarchical_tags' ),
'add_or_remove_items' => __( 'Add or remove tags', 'hierarchical_tags' ),
'choose_from_most_used' => __( 'Choose from the most used', 'hierarchical_tags' ),
'popular_items' => __( 'Popular Tags', 'hierarchical_tags' ),
'search_items' => __( 'Search Tags', 'hierarchical_tags' ),
'not_found' => __( 'Not Found', 'hierarchical_tags' ),
);
// Override built-in WordPress tags
register_taxonomy( 'post_tag', 'post', array(
'hierarchical' => true, // Was false, now set to true
'query_var' => 'tag',
'labels' => $labels,
'rewrite' => $rewrite,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'_builtin' => true,
) );
}
add_action('init', 'hierarchical_tags');

Why is wordpress making a query for attachment instead of taxonomy?

I made a custom post type and I've made a taxonomy registered to the cpt and the standard 'post'. This all works perfect.
Now I needed a 2nd taxonomy for organization reasons. I've simply copied the first one and changed the name and labels.
On the backend it all works normal, but on the front end clicking on it redirects to index.php. If I look via the debug toolbar at the query it is attachment=(term-name) instead of (taxonomy)=(term-name). Does anybody have any idea why wordpress does this? (Or to put it better, how did I make wordpress do this?)
This is how the taxonomies are registered, 'arweb' is the cpt and 'onderwerp' is the normal working taxonomy:
add_action( 'init', 'register_custom_taxonomies' );
function register_custom_taxonomies(){
// ///////////////////// ONDERWERP //////////////////////
$labels = array(
'name' => _x( 'Onderwerpen', 'taxonomy general name' ),
'singular_name' => _x( 'Onderwerp', 'taxonomy singular name' ),
'search_items' => __( 'Zoek Onderwerpen' ),
'popular_items' => __( 'Popular Onderwerpen' ),
'all_items' => __( 'All Onderwerpen' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Onderwerp' ),
'update_item' => __( 'Update Onderwerp' ),
'add_new_item' => __( 'Nieuw Onderwerp' ),
'new_item_name' => __( 'Naam Nieuw Onderwerp' ),
'add_or_remove_items' => __( 'Add or remove onderwerpen' ),
'choose_from_most_used' => __( 'Choose from the most used onderwerps' ),
'not_found' => __( 'No onderwerps found.' ),
'menu_name' => __( 'Onderwerpen' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'onderwerp' ),
);
register_taxonomy( 'onderwerp', array( "arweb","post" ), $args );
register_taxonomy_for_object_type( 'onderwerp', 'arweb' );
///////////////////// English onderwerp /////////////////////////////////////////////
$labels = array(
'name' => _x( 'Subjects', 'taxonomy general name' ),
'singular_name' => _x( 'Subject', 'taxonomy singular name' ),
'search_items' => __( 'Zoek Subjects' ),
'popular_items' => __( 'Popular Subjects' ),
'all_items' => __( 'All Subjecten' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Subject' ),
'update_item' => __( 'Update Subject' ),
'add_new_item' => __( 'Nieuw Subject' ),
'new_item_name' => __( 'Naam Nieuw Subject' ),
'add_or_remove_items' => __( 'Add or remove onderwerpen' ),
'choose_from_most_used' => __( 'Choose from the most used onderwerps' ),
'not_found' => __( 'No onderwerps found.' ),
'menu_name' => __( 'Subjecten' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
//'update_count_callback' => '_update_post_term_count',
'query_var' => true,
//'rewrite' => array( 'slug' => 'english-subject' ),
);
register_taxonomy( 'onderwerp_en', array( "arweb","post" ), $args );
register_taxonomy_for_object_type( 'onderwerp_en', 'post' );
register_taxonomy_for_object_type( 'onderwerp_en', 'arweb' );
}
Try updating your permalinks (by going to Settings .. Permalinks and saving). It's possible the URL is matching an outdated rewrite rule.

Resources