In WordPress, how will you check if specific query has children? This bit of code allows you to check to see if the current category archive page has child categories.
function check_cat_children() {
global $wpdb;
$term = get_queried_object();
$check = $wpdb->get_results(" SELECT * FROM wp_term_taxonomy WHERE parent = '$term->term_id' ");
if ($check) {
return true;
} else {
return false;
}
}
<?php
if (!check_cat_children()) {
//use whatever loop or template part here to show the posts at the end of the line
get_template_part('loop', 'index');
} else {
// show your category index page here
}
?>
Enjoy and Have a fun..!! More WordPress Tips & Tricks.

