Skip to main content
14 votes
Accepted

Check if post has children or not

You can first attempt and get a list of post's children. If the returned value was empty, then the post has no child. Here's how you do it: $args = array( 'post_parent' => get_the_ID(), // ...
Johansson's user avatar
  • 15.4k
7 votes

Get the children of the parent category

Use the code below in your archive.php file. This code will help you: $term = get_queried_object(); $children = get_terms( $term->taxonomy, array( 'parent' => $term->term_id, '...
Violla Queue's user avatar
4 votes
Accepted

is_child() function

/** * Return whether the current page is a child of $id * * Note: this function must be run after the `wp` hook. * Otherwise, the WP_Post object is not set up, and * is_page() will return false. ...
Nathan Johnson's user avatar
4 votes

Check if a post is in any child category of a parent category

If you want any nesting depth, use get_posts. /** * Checks if the post is in one of the categories or any child category. * * @param int|string|array $category_ids (Single category id) or (comma ...
Josef Wittmann's user avatar
3 votes
Accepted

get_children() not working properly – Only on one post?

The get_children function retrieves posts (an upoaded image is also a post) that are dependent on the post with a certain ID. An image becomes a child of a post when it is uploaded while editing that ...
cjbj's user avatar
  • 15k
2 votes

Get the children of the parent category

If there are no values in the array you can try the following approach: $last_categories = get_categories( array( 'taxonomy' => 'product_cat', 'parent' => $sub_category->cat_ID ) ...
croppio.com's user avatar
2 votes

Permalink for PDF of article

Using add_rewrite_endpoint <?php if ( ! class_exists( 'PDFRewriteEndpoint' ) ): class PDFRewriteEndpoint { /** * Add actions and filters in constructor. */ ...
jgraup's user avatar
  • 9,834
2 votes

Display children category images

Haven't tested it, but this should do it. <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $queried_object = get_queried_object(); $term_id = ...
Daniel Fonda's user avatar
2 votes
Accepted

How to display only the direct children of a term on a taxonomy page

You have got the current term id by the following code $current_term_id = get_queried_object_id(); Getting all the info of chilldren of the parent, not grandchildren $termchildren = array( '...
Mohammad Tajul Islam's user avatar
2 votes

`get_terms()` with `child_of` and `childless` combined

OK, so this is what I came up with: function get_childless_term_children( $parent_id, $taxonomy ) { // get all childless $terms of this $taxonomy $terms = get_terms(array( 'taxonomy' => $...
rassoh's user avatar
  • 606
2 votes

Walker class for sub-menu with ACF fields

Yes, if you want to keep using a WP nav menu, a walker is the right way to go. To only affect a certain level (i.e. children, grandchildren, parent, etc.) you can use $depth. class wpseWalker ...
WebElaine's user avatar
  • 9,664
1 vote

Menu walker: how to tell if a sub menu contains submenus?

I can extend the Walker_Nav_Menu class, but after taking a look to it, it seems there's no way to know when an sub-menu will contain other sub-menu, because there's no data available about its ...
La Chouette Informatique's user avatar
1 vote
Accepted

Orderby menu_order not working; menu is sorted on publish date

menu_order doesn't mean the order in which it is used in any given custom menu. It means order by the "Order" attribute as entered in this box: Counterintuitively this attribute is saved into the ...
Jacob Peattie's user avatar
1 vote

is_child() function

So I did this and it works. But @NathanJohnson answer is nicer. function is_child($pageID) { $parentID = wp_get_post_parent_id(get_the_ID()); if( is_page() && $parentID == $pageID ) { ...
Valentin's user avatar
1 vote

Check if a post is in any child category of a parent category

Update for using custom taxonomies: /** * Tests if any of a post's assigned categories are descendants of target categories * * @param int|array $cats The target categories. Integer ID or array of ...
Leander's user avatar
  • 135
1 vote
Accepted

Display Child Pages of Custom Post Type Parent Page

The page itself is a custom post type, you can notice this when you open the edit page screen. Your URL will be like this: www.example.com/wp-admin/edit.php?post_type=page This means you are on a ...
Johansson's user avatar
  • 15.4k
1 vote

How to create template for children category?

I have found answer, based on this post For cases when someone wants to have different template for child category. For example, if you have categories ordered like this: continent->country->city. ...
user3751604's user avatar
1 vote

Showing categories and subcategories with posts

This function works right away, just make sure to change the names to your own taxonomy and post type. Feel free to read the comments for more clarification. function ...
epicrato's user avatar
  • 201
1 vote
Accepted

Showing categories and subcategories with posts

Update: Complete code <ul> <?php $get_parent_cats = array( 'parent' => '0' //get top level categories only ); $...
Bikash Waiba's user avatar
  • 1,784
1 vote
Accepted

How to Display child post on his parent post with thumbnail and content in WordPress

Just to check I understood your question, you want to display child posts under each parent post? In that case you have to write one more WP_Query inside your while loop, with parent as current post ...
Aniruddha Gawade's user avatar
1 vote
Accepted

get_pages displays only parents instead of children

The problem here is twofold. Firstly, you're using 'parent' => $post->ID,. $post is a global variable, not a super global, so you have to state that you intend to use it before doing so with: ...
Tom J Nowell's user avatar
  • 60.6k
1 vote

Prev/Next child navigation for current page?

The 'wpse5422_the_page_siblings()' solution works great, I cannot comment as my rep is too low, but my only change is to make this line: 'sort_column'=>'menu_order', To be this: 'sort_column'=&...
Purple Tentacle's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible