Is it possible to search only pages and not posts? I use pages with custom fields for everything pretty much.
I use posts for some random things and don't want them appearing in my search without a page.
Is it possible to search only pages and not posts? I use pages with custom fields for everything pretty much.
I use posts for some random things and don't want them appearing in my search without a page.
Yes - if you edit your theme's search.php template page.
Edit it in what way? Here's what I'm using for my search code:
<?php $posts=query_posts($query_string .
'&posts_per_page=20'); ?>
<?php if (have_posts()) : ?>
<h1>Search Results</h1>
<?php while (have_posts()) : the_post(); ?>
<h1><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a><br />
</h1>
<?php endwhile; ?>
<?php endif; ?>Try:
<?php $posts=query_posts($query_string . '&posts_per_page=20'); ?>
<?php if (have_posts()) : ?>
<h1>Search Results</h1>
<?php while (have_posts()) : the_post();
if( $post->post_type != 'page' ) continue;?>
<h1><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a><br /></h1>
<?php endwhile; endif; ?>Perfect, thanks!
No problem :-)
This topic has been closed to new replies.