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(), // ...
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,
'...
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.
...
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 ...
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 ...
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
)
...
2
votes
Permalink for PDF of article
Using add_rewrite_endpoint
<?php
if ( ! class_exists( 'PDFRewriteEndpoint' ) ):
class PDFRewriteEndpoint {
/**
* Add actions and filters in constructor.
*/
...
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 = ...
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(
'...
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' => $...
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 ...
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 ...
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 ...
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 ) {
...
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 ...
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 ...
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. ...
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 ...
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
);
$...
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 ...
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:
...
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'=&...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
children × 129categories × 29
custom-post-types × 19
terms × 16
child-pages × 16
menus × 15
pages × 15
custom-taxonomy × 14
taxonomy × 14
wp-query × 13
loop × 11
navigation × 7
hierarchical × 7
wp-list-pages × 7
posts × 6
query × 5
slug × 5
walker × 5
php × 4
images × 4
page-template × 4
get-posts × 4
get-children × 4
css × 3
order × 3