Is it possible to search specific pages and their children?
Question
I want to search certain page IDs and if those pages have children search them as well. Nothing gets displayed though.
My code, search.php
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
// determine parent of current page
if ($post->post_parent)
{
$ancestors = get_post_ancestors($post->ID);
$parent = $ancestors[count($ancestors) - 1];
}
else
{
$parent = $post->ID;
}
$children = get_pages("title_li=&child_of=" . $parent . "&echo=0&sort_column=menu_order");
foreach ($children as $child):
if (get_the_ID() == $child || get_the_ID() == $parent)
{ ?>
<div class="col-xs-12 col-sm-4 item">
<div class="ft-image">
<a href="<?php echo the_permalink(); ?>" style="background-image: url(<?php echo get_the_post_thumbnail_url(); ?>)"></a>
<h3 class="post-title"><?php echo the_title(); ?></h3>
</div>
<div class="content">
<div class="intro">
<?php
// strip tags to avoid breaking any html
$string = strip_tags(get_the_excerpt());
$count = 130;
if (strlen($string) > $count)
{
// truncate string
$stringCut = substr($string, 0, $count);
// make sure it ends in a word so assassinate doesn't become ass...
$string = substr($stringCut, 0, strrpos($stringCut, ' ')) . '...';
}
echo $string;
?>
</div>
<a href="<?php echo the_permalink(); ?>" class="cta-btn"><?php echo __('Learn More', 'TMP'); ?></a>
</div>
</div>
<?php
}
endforeach;
endwhile;
endif;
Also is it possible to make it in ajax?
0
search
4 years
2019-11-05T03:25:22-05:00
2019-11-05T03:25:22-05:00 0 Answers
48 views
0
Leave an answer