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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
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.