11
votes
Accepted
Different template for subcategories
The template hierarchy has filters for all types of templates. Here we can use category_template, check if the current category has a parent, and load the subcategory.php file in that case:
function ...
7
votes
Disable block from editor based on post type
You can use the allowed_block_types hook:
<?php
function wpse_allowed_block_types($allowed_block_types, $post) {
// Limit blocks in 'post' post type
if($post->post_type == 'post') {
...
6
votes
How to display non-hierarchical taxonomy as terms with checkboxes?
Now in 2020, i've found the definitive and simpliest solution:
register_taxonomy( "my_tax", [ "my_post" ], [
...
"meta_box_cb" => "post_categories_meta_box",
] );
You can ...
6
votes
Accepted
Display a list of child posts on parent posts of a custom post type
The best way is using WP_Query. I think your error or plugin error could be that the 'post_type' of childs is not define.
WP Query : https://codex.wordpress.org/Class_Reference/WP_Query
global $...
5
votes
How to show a hierarchical terms list?
I used @popsi code that was working really well and I made it a more efficient and easy to read:
/**
* Recursively sort an array of taxonomy terms hierarchically. Child categories will be
* placed ...
5
votes
Category tree is flattened inside admin upon saving
The plugin can be resumed to this simple code:
add_filter( 'wp_terms_checklist_args', function( $args ) {
$args['checked_ontop'] = false;
return $args;
});
4
votes
get_posts assigned to a specific custom taxonomy term, and not the term's children
Here is complete code hope it helps. Thanks
<?php
$terms_array = array(
'taxonomy' => 'services', // you can change it according to your taxonomy
'parent' => 0 // If parent => 0 ...
4
votes
Categories lose hierarchy order once assigned to post
Based on the plugins Category Checklist Tree and Categories in Hierarchical Order, you could directly use this filter in your function.php file without adding any plugin:
add_filter('...
4
votes
Different template for subcategories
I have edited your code to add more functionality. For cases where someone would want to have a different template for each child category. For example if you have categories ordered like this:
...
4
votes
Accepted
Archive page showing nothing - issue with WordPress Hierarchy?
Your designated 'blog page' (selected in 'Reading') will use the index.php file (or home.php) rather than archive.php file.
3
votes
Accepted
Permalinks for WooCommerce Categories and Subcategories
I was able to resolve this with the following code which generates rewrite_rules for each subcategory, which is preferred during matching since it's more specific:
function ...
3
votes
Accepted
Will renaming a `content.php` file cause any problems?
There shouldnt be any issue, dont forget to change the slug in the template part call:
get_template_part( 'format', get_post_format() );
the best practice is to have them in their own folder:
...
3
votes
Use Drag & Drop Functionality from WordPress Admin Area in the Frontend?
You can enqueue those scripts in your theme to use it. It's all part of jQuery ui;
https://developer.wordpress.org/reference/functions/wp_enqueue_script/
wp_enqueue_script(
array(
'jquery-ui-...
3
votes
Remove base slug in permalinks of hierarchical custom post type
This will allow you to use the post name without the slug. Essentially anytime the link is requested it can be altered to exclude the base post type. And any time a query runs with just a name, the ...
3
votes
Accepted
tax_query: Don’t show posts with parent term when they have a corresponding child term applied
I can see you are trying to be clear but still a really confusingly worded question, broke my brain a bit. I think this might achieve what you want, but I'm not fully sure if I understand you ...
3
votes
Website parent child relationship
They aren't "files" or "folders" per se, but you could achieve that URL structure. Custom code to create custom post types and taxonomies would be the ideal way, as that could then ...
2
votes
How can I allow commas in tag names?
Commas in tag names won't work properly because, when adding the tag to a post, WordPress will parse it as multiple keywords, breaking at the comma.
A simple fix:
Use , (the HTML code for ...
2
votes
Custom taxonomy, get_the_terms, listing in order of parent > child
Inspired by Michal Mau answer and Manny Fleurmond answer here is my solution:
I have the same issue as @Lucas Bustamante: What if the post has two parent categories?
My solution was to create another ...
2
votes
Accepted
Category tree is flattened inside admin upon saving
I haven't fully tested this, but it may be helpful:
Categories in Hierarchical Order plugin at https://wordpress.org/plugins/categories-in-hierarchical-order/
2
votes
Accepted
Hierarchical Custom Post Types - Show only parent on tax archive?
Figured a simple pre_get_posts would do the trick,
It will, you just need to query posts that have a parent of 0.
Assuming your taxonomy slug/name is literally just region:
function ...
2
votes
Hierarchical or Non-hierarchical Custom Post Type in Real World Example
Do you need to be able to have/assign a parent post?
If yes, then use hierarchical, if not then don't.
Hierarchical post types allow you to do one way post to post relations of the type 1:many, ...
2
votes
Accepted
Creating a non-hierarchical Taxonomy that behaves like categories
This blog post by "Gazchap" deals with exactly the situation you are, and they updated it after publishing to your follow-up problem:
Fortunately, version 4.4 of WordPress introduced a ...
2
votes
Accepted
Edit the_category (); for a hierarchical display
You could assign the post only to the child category, and call the function like so:
the_category( ' ', 'multiple' );
This will output (notice the whitepsace between the anchor tags):
<a href=&...
1
vote
Accepted
How to query for posts (hierarchical custom post type) that have children but are NOT top level?
You can use filters to modify the SQL. I added something unique in the post_type so I could filter only this query and not change anything else.
The query for example
$query = new WP_Query(array('...
1
vote
How to display terms from a custom taxonomy in a hierarchy AND with custom html markup?
Solved it with the following Custom Walker:
class CustomWalker extends Walker_Category {
function start_el(&$output, $item, $depth=0, $args=array()) {
$output .= "\n<li><a href=\"http:/...
1
vote
Migrating Hierarchal Taxonomy Categories Between Post Types
So that at least there's a solution here, will add that this plugin seems to succesfully migrate Posts as well as category and hierarchy.: https://wordpress.org/plugins/post-type-convertr.
On the ...
1
vote
Display hierarchical subterms of custom taxonomy based on depth
Found the easiest solution with the get_the_terms() | Function. I really do not have a clue why the figures of level 2 ($terms[2]) and 3 ($terms[1]) are not in the correct order, but at least it is ...
1
vote
Display hierarchical subterms of custom taxonomy based on depth
I love a good challenge!
The function here:
function get_post_categories_sorted ( $post_id ){
$terms = wp_get_post_terms( $post_id, 'category' );
$sorted_terms = [];
foreach( $terms ...
1
vote
Categories vs. Page Site Organization
You could create a customised 'landing page' using a template file?
Creating category-internal.php with custom layout would display content at the /category/internal/ url.
Here is some more info:
...
1
vote
Accepted
Categories vs. Page Site Organization
I switched everything over to a categories model, so that I now have this category hierarchy:
Internal
-- Docs
-- Policy
I'll have to figure out how to customize the /category/internal/ page ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
hierarchical × 260custom-post-types × 113
custom-taxonomy × 86
categories × 41
permalinks × 31
taxonomy × 27
pages × 26
terms × 26
url-rewriting × 11
wp-query × 10
menus × 10
posts × 9
rewrite-rules × 8
archives × 8
plugins × 7
functions × 7
customization × 7
navigation × 7
child-pages × 7
children × 7
template-hierarchy × 6
php × 5
custom-field × 5
loop × 5
templates × 5