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

  • Home
  • SEARCH
  • 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 7542885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:17:12+00:00 2026-05-30T08:17:12+00:00

Below is the code for the Search Results. The search separates page results from

  • 0

Below is the code for the Search Results. The search separates page results from post results.

<?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; ?>

Using the current code, if no search results are found for either Post/Page Search Results, the phrase "No Results" is displayed below the Post/Page Results header(s). This needs to be preserved.

I want to position the header "Post Search Results" and the "Post Results Code" in one div and the header "Page Search Results" and the "Page Results Code" in a separate div that is set inside another div. Like this:

<div id="A">
<div id="B">Post Results header & Post Results Code</div>
<div id="C">Page Results header & Page Results Code</div>
</div>

Where do I insert the div tags in the code to accomplish this? Thank you!

  • 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-30T08:17:13+00:00Added an answer on May 30, 2026 at 8:17 am

    This should do what you want:

    <div id="A">
    <?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') : ?>
        <div id="B">
        <h2 class="pagetitle">Post Search Results</h2>
    <?php else : ?>
        <div id="C">
        <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; ?>
    </div>
    <?php endforeach; ?>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see the jQuery code below, it used to paginate some search results paginate:
Leading on from my last question: Tidying search results from database php My research
I have the following (sample)code to filter search results from a LLBLGen data source:
i am using the code below to highlight the search results: $text = preg_replace(/\b($word)\b/i,
The below code in Java throws Null pointer exception. public class New{ int i;
Currently users can search a database using php and ajax with the results shown
I have 3 pages: search.html. search.php, and edit.php I also have new.php which I
i created a simple search engine that displays mysql database results using the php
I am using a simple live search script that displays the results from a
After retrieving search results from a UISearchBar, the results appear in my tableview correctly,

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.