Hierarchical Custom Post Types

I would like to have the following taxonomy structure: site.com/courses/course-name/pathway/pathway-name The domain is such that any particular course can be completed by taking a number of different pathways - different module structures. The following URLS would work as such: site.com/courses shows a list of courses site.com/courses/course-name will follow a template e.g. single-course.php, showing title, content and a list of the pathways associated to this course. site.com/courses/course-name/pathways/ will follow a template e.g. archive-pathway.php, showing course-name and a list of pathways (not …
Category: Web

Add Product categories to Wordpress menu without losing hierarchy

I need to add product categories to Wordpress menu, but when I'm doing this with WP interface it lose the hierarchy I tried with WP-CLI, but there is no method to specify wich item is the child. There is a method to do it? There is a ton of categories (3-4 level deep), I cannot do this manually I can buy also a plugin. Can you suggest something? Thanks a lot
Category: Web

Custom post type / taxonomy rewrite archive page 2 gives 404

I've followed the code based off this and everything is working perfectly -How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name So I am able to browse taxonomy archives with my/category (or) my/category/subcategory and view a custom post associated with each term as my/category/subcategory/custompost However, I cannot view my/category/page/2/ or my/category/subcategory/page/2/ It gives me a 404. Here is the code I am using. posttype.my.php function create_my_posttype() { register_post_type( 'my', array( 'labels' => array( 'name' …
Category: Web

Create a Hierarchical List of Custom Taxonomies AND Posts

I'd like to create a 3-tier hierarchical list of terms within a custom taxonomy, which includes up to 10 posts within each of the bottom-level term(s) only. e.g. Custom Taxonomy - Parent Term 1 -- Child Term 1 --- Post 1 --- Post 2 -- Child Term 2 --- Post 1 --- Post 2 --- Post 3 --- Post 4 -- Child Term 3 etc I'd like eventually have these display in a set of 'spoilers' or in an 'accordion' …
Category: Web

How to set a 'page' as parent of a custom post type?

For various reasons, I would like to use a 'page' in preference to an archive page for one of our custom post types and have this be reflected in the permalink structure. I am struggling to find out exactly how to do this. What needs to be achieved is a permalink structure that, when viewing a custom post, show as: mysite.com/[page-name]/[custom-post-type-single] I'd be extremely grateful for any help that can be offered. NB I have tried the Post Type Parents …
Category: Web

Templates for hierarchical custom post type

I'm a bit confused with templates for custom post types defined as hierarchical. I've got a CPT set to hierarchical, not strictly in order to have a nested hierarchy, but so that they can be ordered by the Simple Page Ordering plugin. Here's the code: register_post_type( 'case_study', array( 'label' => _x( 'case studies', 'post type plural name' ), 'labels' => array( 'name' => _x( 'Case studies', 'post type general name' ), 'singular_name' => _x( 'Case study', 'post type singular name' …
Category: Web

Permalink with hierarchy of Custom Post Types

We have a site where we have the following structure: www.example.com/volume-number/book-title/chapter-title We do this hierarchy by creating the Chapter pages as child of a Book page, which in turn is child of a Volume page. Now we are moving to using Custom Post Types with the CPT UI plugin. Upon creating a Chapter CPT, the URL displays as follows: www.example.com/chapter/chapter-title Is there a recommended way to recreate that same hierarchy above when using CPTs? Thanks!
Category: Web

Custom Taxonomies not retaining hierarchy while importing from one site to another

On my site I have a Custom Post Type "listing" which has a hierarchial Taxonomy "local". The terms in this taxonomy are in the form of States > Cities. For example "Washington" is a parent term & Arlington, Auburn, Davenport etc could be it's child taxonomies. Now when I export & import this Custom Post Type to another site, my child level taxonomies become top level taxonomies, they no longer retain the hierarchy. I have used code in functions.php to …
Category: Web

Custom post type Permalinks with hierarchical Taxonomies

I Would use Custom Post Type and hierarchical Taxonomies with same Slug. Fortunately I found a good solution based on post_type_link filter here from TheDeadMedic. mysite.com/products/category1/product-name1 mysite.com/products/category2/product-name2 mysite.com/products/category1/subcategory1/product-name1 mysite.com/products/category2/subcategory2/product-name2 ... The only problem is subcategory pages get 404. So these URLs work: mysite.com/products/category1/product-name1 mysite.com/products/category1/subcategory1/product-name1 But subcategory pages don't work in hierarchical structure: mysite.com/products/category1/subcategory1 mysite.com/products/category2/subcategory2 I can only access these subcategories without hierarchical structure. So these URLs work: mysite.com/products/subcategory1 mysite.com/products/subcategory2 Have you got any idea how I could extend TheDeadMedic's solution …
Category: Web

Get count for all terms inside a parent term

I am trying to get the post count for a term and it's child terms. I tried it with pad_count=> true but this seems to have no effect. My term stucture is like the following: - term 1: 10 posts - term 2: 1 post -- subterm 1: 4 posts -- subterm 2: 12 posts - term 3: 4 posts This is my code: $args = array( 'pad_counts' => true ); $terms = get_terms('category', $args); foreach($terms as $term) { var_dump( …
Category: Web

Rewrite Post URL so it is constructed from parent post url & child post url

What I want to achieve: Make Posts (post type 'post') hierarchical (Done - see code below) The child posts should have the following urls: domain.com/parent-slug/child-slug. This is exactly what happens when you use the build in hierarchy for pages but after making posts hierarchical the child posts have the url domain.com/child-slug/ Additional Info: I am aware that this can be achieved with pages and custom post types but I have good reasons that I need it for the post post-type …
Category: Web

How to add a regular page under a custom post type?

I'm building a WordPress website that should have the following structure: Project A (project post type) About (regular page) Location (regular page) Partners (regular page) News (regular page) Project B (project post type) About (regular page) Book (regular page) As you see, each project can have random pages below it. The admin should be able to add any page as he wants. I found some solutions based on setting the hierarchical attribute from my custom post type to true and …
Category: Web

Edit the_category (); for a hierarchical display

For my wp theme I want to use the categories as tags on my posts. Example: The problem is that the category in red must always be the parent and in gold the child. Except that returns the categories to me in alphabetical order and not in hierarchical order, so sometimes I end up with the child in red and the parent in gold ... Knowing that I would only use 2 categories per posts so 1 = the parent …
Category: Web

Product subcat with duplicate name of a subcat of another cat gets the category name in the slug

Suppose the following categories tree in Woo: Men (slug men) -- Shoes (slug shoes / was created first) Women -- Shoes (slug shoes-women / was created second) Why is this happening? Both subcats belong to different categories. Why is the category slug appended to the name of the second duplicate subcat? And anyway, for whatever reason Autommatic decided to program it that way, I need to change it, as the nature of the e-shop I'm building is full of such …
Category: Web

Show subChild categories

Targets : Show Locations (sub-districts & cities) on the customized shop page & on tab additional information - Show on line 5 I'm building a property site using wordpress and woocommerce. In my country has 7 islands, 34 provinces, 514 Cities, 7041 Districts, 82194 Sub-districts. Then I grouped the data and added it to : On category Verified (parent) Sold (parent) Rent (parent) Island #1 (parent) province #1 (child) City #1(sub-child) Island #2 (parent) province #2 (child) City #2(sub-child) Island …
Category: Web

Display custom post type in hierarchical order with get_terms

How can I display a custom post type of products with a custom taxonomy (product category) in a list, in hierarchical order? I'd like to get them in this order: h3.parentcategory 1 -h4.childcategory 1 -li.product of childcategory 1 -li.product of childcategory 1 -h4.childcategory 2 -li.product of childcategory 2 -li.product of childcategory 2 h3.parentcategory 2 -h4.childcategory 1 of parent 2 Unfortunately I can't wrap my head around the second level (childcategory 1 & 2). I'm using this code to display category …
Category: Web

Get the the top-level parent of a custom taxonomy term

How would I get the top-level parent of a given term? I am using wp_get_object_terms to get taxonomy terms on posts, but instead of showing all tagged terms, I only want to show tagged terms' top-level parents. So if these are my selected terms, I only want to show Breakfast, Lunch and Dinner. x BREAKFAST x Cereal x Eggs LUNCH Hamburger x Pizza DINNER Fish Bass x Salmon Trout Lasagna How can I do this?
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.