Few things –
Relation is not needed.
-
It only works between multiple’s of the same type of query (meta OR
tax) it explicitly says in the codex under custom_meta queries to
not use this with a single inner meta query -
Even if you had 2 queries AND is considered the default you really only need to specify OR
Your method of querying the taxonomy is wrong for 1.5 reasons
- Definitely wrong: you’re using the term’s name property when by default it queries by slug
- Half wrong: this method has been depreciated in favour of tax_query
Other things:
You’re using a variable that should be reserved for the main query
You’re resetting the query when all you need to be doing is resetting the post data
Unset does not need to be called on $term.
Also do you really want pagination? from your explanation it doesn’t sound like you do, but that’s easily changed..
Here’s some code with a few updates, let me know how it goes.
<?php
$termID = 8; // Parent A ID
$taxonomyName = "product_category";
$termchildren = get_term_children( $termID, $taxonomyName );
foreach ($termchildren as $child) {
$term = get_term_by( 'id', $child, $taxonomyName );
echo "<h2>".$term->name."</h2>";
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$my_query = new WP_Query( array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => $taxonomyName,
'field' => 'slug',
'terms' => $term->slug
)
),
'meta_query' => array(
array(
'key' => 'product_active',
'value' => '1'
),
),
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'paged'=> $paged
)); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php the_title(); ?> <img src="https://wordpress.stackexchange.com/questions/145038/<?php $image = wp_get_attachment_image_src(get_field("product_image'), 'full'); ?><?php echo $image[0]; ?>" alt="<?php the_title(); ?>" /><br />
<?php the_content();
endwhile;
wp_reset_postdata();
}
?>