I have been stressing over this for a while. I have figured out how to call pages in a loop using custom taxonomies. I have also figured out how to call child pages of a parent page in a loop. However, what I would like to do is call the child pages, then filter out the child pages that belong to a custom taxonomy, as to only show these ones.
Thanks in advance for any help,
I can offer any more information needed,
The child page code:
<?php
$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT' ); ?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
<div class="comparison-post-block"><div class="wrapper"><div class="top-5-image">
<?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?>
</div></div>
<div class="comparison-top5-text">
<div class="wrapper"><div class="top-5-title"><p class="comparisontitle">
<a class="comparisontitle" href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a>
</p> </div></div>
<div class="wrapper"><div class="comparison-content"><div class="comparisonexcerpttext">
<?php echo get_the_excerpt($pageChild->ID); ?>
</div></div></div></div></div>
The custom taxonomy code:
<?php
if ( is_page() ) {
global $post;
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'top5',
'field' => 'name',
'terms' => $post->post_title
)
)
);
$My_Query = new WP_Query( $args );
?>
<?php if ( $My_Query->have_posts() ) : ?>
<?php rewind_posts(); ?>
<?php while ( $My_Query->have_posts() ) : $My_Query->the_post(); ?>
<div class="comparison-stories"><div id="comparison-container_division">
<div class="comparison-post-block"><div class="wrapper">
<div class="top-5-image">
<?php the_post_thumbnail('medium'); ?></div></div>
<div class="comparison-top5-text">
<div class="wrapper"><div class="top-5-title"><p class="comparisontitle">
<a class="comparisontitle" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> </div> </div>
<div class="wrapper"><div class="comparison-content"><div class="comparisonexcerpttext">
<?php the_excerpt(); ?></div></div></div></div></div></div>
<?php endwhile; ?>
<?php else:
// Your fallback content here
?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
<?php wp_reset_query(); ?>
<?php } ?>
As far as I am aware I have copied all of the code into here,
Sorry this is my first post so not exactly sure how you would like the code, so essentially I would like to combine these two pieces of code!
Thanks again!