WordPress - Breadcrumb NavXT issue with categories - php

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);
}

Related

How to display custom post for user only in wordpress

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.

Display custom post type taxonomies as an archive page

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

How to change URL in Wordpress according to taxonomy name

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.

Wordpress: how to rename / rewrite taxonomy name

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?

How to include excerpt option on taxonomy category page?

I am trying to add an excerpt option to my category page, to display instead of my description.
So basically, I need a box on this screen which will be able to be used as preview text.
The code used to create this taxonomy is:
add_action( 'init', 'create_product_cat_external' );
function create_product_cat_external() {
register_taxonomy(
'ExternalProducts',
'products',
array(
'label' => __( 'External Products' ),
'rewrite' => array( 'slug' => 'externalproducts' ),
'hierarchical' => true,
)
);
}
and the box needs to be here:
You can use CMB2 plugin and put this in your functions.php for example:
add_action( 'cmb2_admin_init', 'yourprefix_register_taxonomy_metabox' );
function yourprefix_register_taxonomy_metabox() {
$prefix = 'yourprefix_term_';
$cmb_term = new_cmb2_box( array(
'id' => $prefix . 'edit',
'object_types' => array( 'term' ), // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => array( 'products'), // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
) );
$cmb_term->add_field( array(
'name' => __('Excerpt', 'default'),
'id' => $prefix . 'excerpt',
'type' => 'wysiwyg',
'on_front' => false,
) );
}

Categories