Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6918931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:55:23+00:00 2026-05-27T09:55:23+00:00

The following is my search.php: <?php if (have_posts()) : ?> <h2 class=pagetitle>Page Search Results</h2>

  • 0

The following is my search.php:

<?php if (have_posts()) : ?>
    <h2 class="pagetitle">Page Search Results</h2>
    <?php while (have_posts()) : the_post(); ?>
        <?php if ($post->post_type == 'page') : ?>
             Show Page results
        <?php endif; ?>
    <?php endwhile; ?>

    <?php rewind_posts(); ?>
    <h2 class="pagetitle">Post Search Results</h2>
    <?php while (have_posts()) : the_post(); ?>
        <?php if ($post->post_type != 'page') : ?>
             Show non-page results
        <?php endif; ?>
    <?php endwhile; ?>

<?php else : ?>
 No Results
<?php endif; ?>

The code allows search results under posts to be separated from those found in pages. If no search results are found for either posts or pages, the text “No Results” is displayed.

However, when results are found for pages but NOT posts (and vice versa), under the ‘Post Search Results” there is nothing displayed. I would like the code tweaked so that if there are no results found under “Post Search Results” but there are results found under “Page Search Results,” the text “No Results” is displayed underneath the “Post Search Results” header.

Thanks a lot everyone.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:55:23+00:00Added an answer on May 27, 2026 at 9:55 am

    Give this a try, you can expand the array to include any post_type your site is using:

    <?php
        foreach (array('post','page') as $pt) :
            $search_query = new WP_Query(array(
                    'post_type'         => $pt,
                    's'                 => $s,
                    'posts_per_page'    => 10,
                    'paged'             => $paged
                )
            );
        ?>
        <?php if ($pt == 'post') : ?>
            <h2 class="pagetitle">Post Search Results</h2>
        <?php else : ?>
            <h2 class="pagetitle">Page Search Results</h2>
        <?php endif; ?>
        <?php 
            if ($search_query->have_posts()) : while ($search_query->have_posts()) : $search_query->the_post();
            if ($pt == 'post') :
        ?>
            Post Results Code
        <?php else : ?>
            Page Results Code
        <?php endif; ?>
        <?php endwhile; else : ?>
            No Results
        <?php endif; ?>
    <?php endforeach; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following code: <form action=process.php method=POST> <fieldset class=form-search> <input type=text class=input-text
for the following form <form action ='search.php' method = 'post'> <select name=filter> <option id=A
I have a search page with the following scenarios listed below. I was told
i have the following code for search from database show return result to the
I have the following mod_rewrite rule: RewriteRule ^([^/.]+)/?$ search.php?action=procedure&procedureName=$1 This works fine in redirecting
I have the following URL: http://somedomain.com/aa/search/search.php I want it to return 2 selections, that
I have the following code $content .= ' <div id=myDivID>'; include 'search.php'; $content .=
I am trying to build an SQL Statement for the following search scenario: I
I get this message: Cannot find the X.509 certificate using the following search criteria:
I am using the following to search for a file defined as a macro

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.