I’m trying to write a search feature on a website of mine, and it seems like it’s not pulling in any of the pages, only posts. Below is the code.

Search Form:

          <form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
                <input type="text" value="Search" onblur="if (this.value == '') {this.value = 'Search';}" onfocus="if (this.value == 'Search') {this.value = '';}" name="s" id="messagesSearch" />
                <input type="hidden" name="post_type" value="postpage" />
                <img src="<?php bloginfo('template_directory'); ?>/includes/images/icons/search-light.svg" alt="">
          </form>

Search:

  <?php
       if(isset($_GET['post_type'])) {
           $type = $_GET['post_type'];
           if($type == 'postpage') {?>
            <?php if (have_posts()) : ?>
                    <?php /* Start the Loop */ ?>
                    <?php while ( have_posts() ) : the_post(); ?>
            <?php if ((get_post_type( $post ) == 'post') || (get_post_type( $post ) == 'page')) : ?>
            <?php the_title(); ?>
            <?php endwhile; endif; ?>
            <?php } } ?>

Read more here: WordPress search for pages


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, ,

Wordpress related questions and answers: