I have created following taxonomy in wordpress function:
add_action( 'init', 'create_book_tax' );
function create_book_tax() {
register_taxonomy(
'site_players',//taxonomy name
array( 'milan','manu),//CP name
array(
'label' => __( 'Players' ),
'rewrite' => array( 'slug' => 'players' ),
'hierarchical' => true,
'show_in_nav_menus' => true,
'show_admin_column' => true,
)
);
}
add_action( 'init', 'codex_custom_init' );
Now I need to rename it or better to rewrite it changing the name into site_no_players.
There is a way to do it in WP?
Related
I am new in wordpress, i created custom post type and i want this should display only for subscriber only(not for admin ) So how can i do this Here is my current code?
function create_posttype() {
register_post_type( 'UserProject',
array(
'labels' => array(
'name' => __( 'UserProject' ),
'singular_name' => __( 'UserProject' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'UserProject'),
'show_in_rest' => true,
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
if ( current_user_can( 'editor' ) && is_user_logged_in()) {
function book_setup_post_type() {
$args = array(
'public' => true,
'label' => __( 'Books', 'textdomain' ),
'menu_icon' => 'dashicons-book',
);
register_post_type( 'book', $args );
}
add_action( 'init', 'book_setup_post_type' );
}
Book is a custom post type you can write your own code here.
Subscribers have no rights to the dashboard. You can set the condition for editor rule or another rule.
Hello I have a custom post type called results. I also created categories for that specific post type using a taxonomy. I'm not sure if I set it up correctly, but the code I have works so I'm sticking with it. If you see a better way or any errors please let me know.
I am able to create a custom post and set a category to it. Next I would like to create a categories page that will act like the regular archive.php but just for the category of the custom post types.
So say I have a custom post for results and I have its category set to car accidents I would like a way to display them all just like archive.php does for normal posts.
I tried going to a url like this but I get sent to a 404 page, even though I have an archive-results.php
www.myurl.com/results/categories/car-accidents
Here is the code I used to set up the custom post type and the taxonomy. Sorry If its long but I feel like its necessary to include everything.
// Create custom post type
function create_posttype() {
register_post_type( 'Results',
array(
'labels' => array(
'name' => __( 'Results' ),
'singular_name' => __( 'Results' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'results'),
'taxonomies' => array( 'results', 'result-category' ),
)
);
}
add_action( 'init', 'create_posttype' );
//Create category for specific post type
function tr_create_my_taxonomy() {
register_taxonomy(
'results-categories',
'results',
array(
'label' => __( 'Result Categories' ),
'rewrite' => array( 'slug' => 'result-category' ),
'hierarchical' => true,
'has_archive' => true
)
);
}
add_action( 'init', 'tr_create_my_taxonomy' );
Am I missing something that is preventing this url from working?
www.myurl.com/results/categories/car-accidents
Thanks in advance
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'nav_menu_item', 'cmc-description'
));
return $query;
}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
// Create custom post type
function create_posttype() {
register_post_type( 'Results',
array(
'labels' => array(
'name' => __( 'Results' ),
'singular_name' => __( 'Results' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'results'),
'taxonomies' => array( 'results', 'result-category' ),
)
);
flush_rewrite_rules();
}
add_action( 'init', 'create_posttype' );
//Create category for specific post type
function tr_create_my_taxonomy() {
register_taxonomy(
'results-categories',
'results',
array(
'label' => __( 'Result Categories' ),
'rewrite' => array( 'slug' => 'result-category' ),
'hierarchical' => true,
'has_archive' => true
)
);
}
add_action( 'init', 'tr_create_my_taxonomy' );
i Just made this changes can you please copy this to your code and see it runs well or not
When I wrote a taxonomy for my WP site I made a misstake writing the name:
www.mysite.com/clubs/milan
Clubs is the taxonomy name as shown below:
add_action( 'init', 'create_book_tax' );
function create_book_tax() {
register_taxonomy(
'player_clubs',//taxonomy name
array( 'teams'),//CP name
array(
'label' => __( 'Clubs' ),
'rewrite' => array( 'slug' => 'clubs' ),
'hierarchical' => true,
'show_in_nav_menus' => true,
'show_admin_column' => true,
)
);
}
Instead of having www.mysite.com/clubs/milan I would like to replace clubs into games
How can I do it?
I don't worked with wordpress that match but I thing the solution is the bellow code:
add_action( 'init', 'create_book_tax' );
function create_book_tax() {
register_taxonomy(
'player_clubs',//taxonomy name
array( 'teams'),//CP name
array(
'label' => __( 'Clubs' ),
'rewrite' => array( 'slug' => 'games' ),
'hierarchical' => true,
'show_in_nav_menus' => true,
'show_admin_column' => true,
)
);
}
As the other users has point out, you have to flush permalinks in wordpress after you made this change. Or simply type:
flush_rewrite_rules();
after your php function call.
I am having some major issues with this plugin
https://wordpress.org/plugins/breadcrumb-navxt/installation/
I have this layout to my site. In my functions.php file, I have created some new categories inside 'Products' using the following code:
add_action( 'init', 'create_product_cat_scaffolding' );
function create_product_cat_scaffolding() {
register_taxonomy(
'ScaffoldingProducts',
'products',
array(
'label' => __( 'Scaffolding Products' ),
'rewrite' => array( 'slug' => 'scaffoldingproducts' ),
'hierarchical' => true,
)
);
}
add_action( 'init', 'create_product_cat_fencing' );
function create_product_cat_fencing() {
register_taxonomy(
'FencingHoardings',
'products',
array(
'label' => __( 'Fencing Hoardings' ),
'rewrite' => array( 'slug' => 'fencinghoardings' ),
'hierarchical' => true,
)
);
}
add_action( 'init', 'create_product_cat_groundworks' );
function create_product_cat_groundworks() {
register_taxonomy(
'Groundworks',
'products',
array(
'label' => __( 'Groundworks' ),
'rewrite' => array( 'slug' => 'groundworks' ),
'hierarchical' => true,
)
);
}
add_action( 'init', 'create_product_cat_Safety' );
function create_product_cat_Safety() {
register_taxonomy(
'Safety',
'products',
array(
'label' => __( 'Safety' ),
'rewrite' => array( 'slug' => 'safety' ),
'hierarchical' => true,
)
);
}
add_action( 'init', 'create_product_cat_access' );
function create_product_cat_access() {
register_taxonomy(
'Access',
'products',
array(
'label' => __( 'Access' ),
'rewrite' => array( 'slug' => 'access' ),
'hierarchical' => true,
)
);
}
Which creates the following:
From here, I have added sub categories to each of these, for example:
And then when I create products, I just select which sub category they apply to.
Now - my issue. When I click onto my Safety page, the plugin works fine, it goes:
My Site > Safety
But then If I click onto a sub category from Safety, such as Safety category, instead of the breadcrumb going to:
My Site > Safety > Safety Category
It goes to
My Site > Safety
Does anyone have any ideas?
In the plugin, the settings there is an option for Taxonomies, which shows this:
<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" title="Go to the %title% Safety archives." href="%link%">%htitle%</a></span>
Follow these steps
go to Setting > Permalinks > Select Custom Structure
add this into textbox /%category%/postname
hope this will help
Control what's happened in Breadcrumb-NavXT/class.bcn_breadcrumb_trail.php at fill() function line 855.
else if(is_archive())
{
$type = $wp_query->get_queried_object();
//For date based archives
if(is_date())
{
$this->do_archive_by_date();
}
else if(is_post_type_archive() && !isset($type->taxonomy))
{
$this->do_archive_by_post_type();
}
//For taxonomy based archives
else if(is_category() || is_tag() || is_tax())
{
$this->do_archive_by_term();
}
$this->type_archive($type);
}
i am create a wordpress plugin, this plugin add custompost but this post not see featured image
add_theme_support('post-thumbnails',array('km-lightbox','post'));
add_action( 'init', 'create_posttype_light_box' );
function create_posttype_light_box() {
register_post_type( 'km-lightbox',
array(
'labels' => array(
'name' => __( 'Lightboxs' ),
'singular_name' => __( 'lightbox' )
),
'public' => true,
'supports'=> array('title', 'editor','thumbnail' ),
'has_archive' => true,
'rewrite' => array('slug' => 'lightbox')
)
);
}