How to get taxonomy category in permalink for each taxonomy OR How to give a parent page to a given taxonomy?

This worked for me (tested):

add_action( 'init', static function () {
    register_taxonomy( 'portfolio-work', 'post', array(
        'hierarchical' => true,
        'labels'       => array(
            'name'          => 'Portfolio Works',
            'singular_name' => 'Portfolio Work',
        ),
        'rewrite'      => array(
            'slug'       => 'work',
            'with_front' => false,
        ),
    ) );
} );

Then created new pages titled “Blog” (slug: blog) and “Work” (slug: work), and was able to access the pages and taxonomy pages:

  • Permalinks: /blog/%postname%/
  • Page “Blog”:
    http://wpse417869.local/blog/
  • Post “Hello world!”:
    http://wpse417869.local/blog/hello-world/
  • Page “Work” (taxonomy index):
    http://wpse417869.local/work/
  • Term “Portfolio Work A” in “Portfolio Work” taxonomy (term index):
    http://wpse417869.local/work/portfolio-work-a/

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)