'Proj" /> 'Proj" /> 'Proj"/>

Wordpress: Problems with CPT, category and nice permalinks

22 views Asked by At

I set up a Custom Post Type called "projects" and have an archive-projects.php and single-projects.php that work fine.

$args = array(
        'label'             => 'Projects',
        'public'            => true,
        'show_in_nav_menus' => true,
        'has_archive'       => true,
        'supports'          => array('title', 'editor', 'thumbnail'),
        'taxonomies'        => array('category', 'post_tag',),
        'rewrite'           => array('slug' => 'projects'),
        'with_front'        => true,
);
register_post_type('projects', $args);

My aim is to filter projects in archive-projects.php or somewhere else by category. Normally I would use the category-function of WP, correct? So I set up categories associated to projects like cat1, cat2 etc.

However, when I call the categories from the backend they show the URL /category/cat1/ I can change this in settings/permalinks to any word but there are several problems:

  1. I cannot change the category base to "projects" I belive there is a conflict with the CPT called "projects"
  2. the link to the categories calls the category.php not the category-projects.php
  3. in category.php no projects are found. I would need to set up a new query whick makes no sense

Is there a way to achieve a proper display and nice permalinks for projects and categories like /projects/project1/ and /projects/cat1/ ?

My approach so far is to set up a custom ACF-Field for the projects to categorize these. So I can show categories with an URL like /projects/?cat=cat1 in the archive-projects.php by manipulating the query according to the parameter. This works fine but I would prefer to have a nice URL like /projects/cat1/ Perhaps I can do this with rewrite?

Which approach is best and how could I proceed?

Thanks for help in advance!

0

There are 0 answers