0

Hi there having a problem with my search results page - basically it is listing all pages rather than narrowing it down to only those involving the search query.

I suspect I need to make use of get_search_query Is there something I can put in my args so that the search query is used in query_posts?

<?php 
  $args =  array('post_type'=>array('page'), 'posts_per_page' => 6 );

  query_posts($args);

  if ( have_posts() ) : while ( have_posts() ) : the_post();

?>


<a href="<?php the_permalink();?>" title="<?php the_title();?>"><?php the_title();?></a>


<?php endwhile; ?>
<?php else :  // no results?>
    <p>No Pages Found.</p>
<?php endif; ?> 
0

I figured it out with some research

See the updated args

      $s = isset( $_GET["s"] ) ? $_GET["s"] : "";

  $args = array(
    's' => $s,
    'post_type'=>array('page'),
    'posts_per_page' => 6 
    );

  query_posts($args);


  if ( have_posts() ) : while ( have_posts() ) : the_post();
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.