• Resolved BackuPs

    (@neo2k23)


    
    class myCustom_Post{
    	
    public $default_portfolio_slug; 
    
    public $post_type_portfolio = 'portfolio';
    public $post_type_taxonomy_portfolio = 'portfolio_category';
    
    	public function __construct() {
    
    			add_action( 'init', array(&$this,'portfolio'), 12);
    		}
    
    	function portfolio(){
    
    			// Default Slug Names			
    			$default_portfolio_slug              =  'portfolio';
    
    			// Slug Names			
    			$portfolio_slug              = 'portfolio';		// singular portfolio item
    			
    			$labels = array(
    				'name' => _x('Portfolio items', 'post type general name', 'theme_admin' ),
    				'singular_name' => _x('Portfolio Item', 'post type singular name', 'theme_admin' ),
    				'add_new' => _x('Add New', 'portfolio', 'theme_admin' ),
    				'add_new_item' => __('Add New Portfolio Item', 'theme_admin' ),
    				'edit_item' => __('Edit Portfolio Item', 'theme_admin' ),
    				'new_item' => __('New Portfolio Item', 'theme_admin' ),
    				'view_item' => __('View Portfolio Item', 'theme_admin' ),
    				'search_items' => __('Search Portfolio Items', 'theme_admin' ),
    				'not_found' =>  __('No portfolio item found', 'theme_admin' ),
    				'not_found_in_trash' => __('No portfolio items found in Trash', 'theme_admin' ), 
    				'parent_item_colon' => '',
    				'menu_name' => __('Portfolio items', 'theme_admin' ),
    			);
    			
    			$capabilities = array(
    				'publish_posts' => 'theme_publish_portfolios',
    
    				'edit_post' => 'theme_edit_portfolio',
    				'edit_posts' => 'theme_edit_portfolios',
    				'edit_private_posts' => 'theme_edit_private_portfolios',
    				'edit_published_posts' => 'theme_edit_published_portfolios',
    				'edit_others_posts' => 'theme_edit_others_portfolios',
    				
    				'delete_post' => 'theme_delete_portfolio',
    				'delete_posts' => 'theme_delete_portfolios',
    				'delete_private_posts' => 'theme_delete_private_portfolios',
    				'delete_published_posts' => 'theme_delete_published_portfolios',
    				'delete_others_posts' => 'theme_delete_others_portfolios',
    
    				'read_post' => 'theme_read_portfolio',
    				'read_private_posts' => 'theme_read_private_portfolios',
    			);
    			
    			$args = array(
    				'labels'            => $labels,
    				'singular_label' => __('portfolio', 'theme_admin' ),
    				'public' => true,
    				'publicly_queryable' => true,
    				'exclude_from_search' => false,
    				'show_ui' => true,
    				'show_in_menu' => true,
    				//'menu_position' => 20,
    				'capability_type' => 'portfolio',
    				'capabilities' => $capabilities,
    				'hierarchical' => false,
    				'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'comments', 'author', 'page-attributes', 'revisions'),
    				'has_archive' => true,
    				'rewrite' => array( 'slug' => ! empty($portfolio_slug) ? $portfolio_slug : $default_portfolio_slug, 'with_front' => true, 'pages' => true, 'feeds'=>true ),
    				'query_var' => true,
    				'can_export' => true,
    				'show_in_nav_menus' => true,
    			);
    
    			register_post_type('portfolio',$args);
    			
    			// Portfolio Categories
    			
    			$labels_cat = array(
    				'name' => _x( 'Portfolio Categories', 'taxonomy general name', 'theme_admin' ),
    				'singular_name' => _x( 'Portfolio Category', 'taxonomy singular name', 'theme_admin' ),
    				'search_items' =>  __( 'Search Categories', 'theme_admin' ),
    				'popular_items' => __( 'Popular Categories', 'theme_admin' ),
    				'all_items' => __( 'All Categories', 'theme_admin' ),
    				'parent_item' => null,
    				'parent_item_colon' => null,
    				'edit_item' => __( 'Edit Portfolio Category', 'theme_admin' ), 
    				'update_item' => __( 'Update Portfolio Category', 'theme_admin' ),
    				'add_new_item' => __( 'Add New Portfolio Category', 'theme_admin' ),
    				'new_item_name' => __( 'New Portfolio Category Name', 'theme_admin' ),
    				'separate_items_with_commas' => __( 'Separate Portfolio category with commas', 'theme_admin' ),
    				'add_or_remove_items' => __( 'Add or remove portfolio category', 'theme_admin' ),
    				'choose_from_most_used' => __( 'Choose from the most used portfolio category', 'theme_admin' ),
    				'menu_name' => __( 'Categories', 'theme_admin' ),
    			);
    			$capabilities_cat = array(
    				'manage_terms' => 'theme_manage_portfolio_terms',
    				'edit_terms'   => 'theme_edit_portfolio_terms',
    				'delete_terms' => 'theme_delete_portfolio_terms',
    				'assign_terms' => 'theme_assign_portfolio_terms',
    			);
    			
    			
    			$args_cat= array(
    				'hierarchical' => true,
    				'labels' => $labels_cat,
    				'capabilities' => $capabilities_cat,
    				'public' => false,
    				'show_in_nav_menus' => false,
    				'show_ui' => true,
    				'show_tagcloud' => false,
    				'query_var' => true,
    				'rewrite' => false,
    				'show_admin_column' => true,
    			);
    			
    			register_taxonomy('portfolio_category','portfolio', $args_cat);
    			
    	}
    }
    new myCustom_Post();

    Please add the above code to the functions.php of twenty twenty theme

    1) activate the 20-20 theme and save the permalinks just once.

    2) Now create two categories for the portfolio items one named videos and one named animals.

    3) Now add a new portfolio item just give it any name and set the animals category to that newly created portfolio post and in the post content itself add the yoast breadcrumb shortcode. Publish the post.

    4) If you view the post in the front you will see a empty page and the content showing the breadcrumbs path with categories/taxonomy in it.

    afbeelding

    5) Note: in the Yoast Breadcrumb settings there is no setting for the Taxonomy Portfolio as the rewrite has been set to False. So there is nothing to set for this taxonomy (enable or disable). But the taxonomy still shows up in the breadcrumb path.

    Although the categories have no rewrite why does the animal category show up in the breadcrumbs path as a link?

    Why is there a breadcrumb path called ‘Portfolio items’ linking to the last portfolio category called video’s? Rerwite has been set to false!

    The breadcrumb path called ‘Portfolio items’ linking to the last portfolio category called video’s shows up because the register_post_type has a argument called has_archive=> true but the rewrite has been set to false. It should follow the rewrite and not the has_archive in this case.

    Where am i making the mistake or where is yoast breadcrumbs making the mistake and adding the categories to the path. In the Yoast breadcrumb settings the custom category is not shown which is correct because of the rewtite=false.

    Please advice how to resolve this. Thank you



Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Maybellyne

    (@maybellyne)

    Hello @neo2k23

    Thanks for reaching out and for providing detailed replication steps. However, there seem to be an issue with this line:

    public $default_portfolio_slug;

    syntax error, unexpected token “public”, expecting end of file

    I used the CPT UI plugin to create a CPT named portfolio item and a taxonomy portfolio_category by following steps 2 & 3 but couldn’t replicate step 4. My breadcrumb path is Home???Portfolio Items???Arctic fox. See screenshot. However, I set rewrite for the taxonomy as true. So I changed it to false and nothing changes. My breadcrumb path remains the same without the portfolio_category showing. And portfolio item links to the Portfolio archive page.

    Since this is specific to your site/setup, I’d recommend testing again on a fresh WordPress installation. You can get started here.

    Do let us know how it goes.

    Thread Starter BackuPs

    (@neo2k23)

    Hi

    Thank you for the feedback. I just retried (and i was using a clean install before) I will retry and narrow down when the issue occurs and get back to you.

    • This reply was modified 1 year, 10 months ago by BackuPs.
    Thread Starter BackuPs

    (@neo2k23)

    You are right. The issue is caused by something else. I have to figure out which plugin is doing this. I restarted again on a complete fresh install and now it is ok.

    Thread Starter BackuPs

    (@neo2k23)

    I am sorry i have one last question left. How to get rid of the “Portfolio Items” linking to the portfolio post type in single portfolio post pages? There is no setting like for the taxonomy to set that to “none”.

    Thread Starter BackuPs

    (@neo2k23)

    I found the “bug”…. If you enable rewrite for the portfolio taxonomies and in the yoast breadcrumbs settings you have set the category to the breadcrumbs path for the single portfolio items in the setting below.

    Breadcrumbs for post types

    Choose which Taxonomy you wish to show in the breadcrumbs for Post types.

    Then once you switch back to rewrite is false the category keeps on showing in the breadcrumbs path.

    I was using a theme before that had portfolio items which had rewrite enabled for the portfolio taxonomy. Once i switch to the theme that has the taxonomy rewrite disabled (false). That setting is still aplied, but gone in the yoast settings. Checkout the images.

    https://share.getcloudapp.com/Qwu8zj2n

    https://share.getcloudapp.com/llu7bg6d

    This is a believe a bug in the yoast seo plugin. It should check the rewrite and follow that. Note this only happens when cpt’s have the same slugnames and are switched.

    Note: I am not using them together. I just swapped themes which by accident had the same cpt type. One with rewrite and one without.

    And that is also when the “Portfolio Items” gets into the breadcrumbs path of the single portfolio item. I haven’t figured that one out yet. But it has todo with the swap from rewrite => slug name to rewrite => false and settings that have been set in the yoast breadcrumbs in between the swap and which are gone after the swap.

    I still believe that when rewrite had been set to FALSE the “Portfolio Items” pointing to the portfolio archive page should not show up in the breadcrumbs path even when has_archive has been set to TRUE as there is no archive page for the portfolio type.

    Plugin Support Maybellyne

    (@maybellyne)

    Related conversation here

    Thread Starter BackuPs

    (@neo2k23)

    @maybellyne these are completely two different issues. They are somehow overlapping but have significant different problems.

    The issue here is that when you swap themes with same cpt types with same slug names the yoast picks up settings for the cpt type with rewrite whereas the last activated cpt that has no rewrite settings.

    The plugin should follow the rewrite settings for the taxonomy regardsless what is already in your tables.

    Please handle them seperately. Thank you and kind regards.

    Plugin Support Maybellyne

    (@maybellyne)

    Hello @neo2k23 , my bad, I thought it was the same issue with the other one you opened this morning.

    Since I had issues creating the CPT & taxonomy with the code you shared, can you share the whole functions.php with Pastebin so I copy and paste to start the troubleshooting from scratch?

    I look forward to hearing from you.

    Thread Starter BackuPs

    (@neo2k23)

    I will clear the yoast seo tables after theme swap and solve the issue myselves. Thank you for your efford of helping me. I already spend so much time on this that i have to focus on more important matters. And just flushing the yoast seo index tables on theme swap is much easier. Please close the matter. Thank you!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘taxonomy category shows up in breadcrumbs path with rewrite = false’ is closed to new replies.