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 6952701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:22:59+00:00 2026-05-27T14:22:59+00:00

I am working on searching in wordpress i want to search text in multiple

  • 0

I am working on searching in wordpress i want to search text in multiple categories. here is my code

<form method="post" action="<?php bloginfo('home');?>/?ptype=catsearch" >
    <input type="text" name="searchtext" size="40" />
        <h2><?php _e('Categories:'); ?></h2>
        <select name="category[]" multiple='multiple'> 
            <option value=""><?php echo esc_attr(__('Please Select Your Choice')); ?></option> 
                <?php $categories=  get_categories('show_count=0&orderby=name&echo=0&hierarchical=true&depth=1&taxonomy=category&exclude=1'); 
                foreach ($categories as $category) {
                $option = "<option value=$category->term_id>";
                $option .= ucfirst($category->cat_name);
                $option .= '</option>';
                echo $option;
            }
            ?>
        </select>
    <input type="submit" id="searchsubmit" value="Search" name="submit"/>   
</form> 

when this foms posts on catsearch.php file i takes all categoryids in array and create url see code below. if muliple categories selected it creates url like http://abcd.com/?cat=3&cat=7&cat=8&s=dasdasDS. In this case it search the text only in last cat id. I think it overights the catids. I need if my search text found in any category then all posts should be displayed.

$categoryids = $_POST['category'];

            echo 'count is ---' .count($categoryids); 

            if($categoryids)
            {
                foreach($categoryids as $categoryid)
                {
                    $cat.=  'cat='.$categoryid.'&';
                }
                echo $cat = trim($cat, '&');
                echo '<br />';
                 $url .= '?'.$cat;

            }
if($_POST['searchtext'])
            {
                echo 'searchtext---'. $_POST['searchtext'];
                echo '<br />';
                $url .= '&s='.$_POST['searchtext'];
            } 
<META http-equiv="refresh" content="1;URL=<?php echo get_bloginfo('url')."$url"; ?>">
  • 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-27T14:23:00+00:00Added an answer on May 27, 2026 at 2:23 pm

    When you are doing something like this

    cat=3&cat=7&cat=8
    

    You are constantly redefining the value of $_GET[‘cat’]. So it makes perfect sense that it would end up being the last one – 8.

    The syntax for querying multiple categories in wordpress is using a comma

    cat=3,7,8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a small project which involves a dictionary based text searching
Trying to get searching working on Heroku using partial search The following query generates
Well m searching hard on google but unable to find any working code that
Below is my code, after searching and working all night, I finally figured how
Ok, i was searching but there wasn't any method that was working for me.
I'm working on a grep-like utility in Python for searching Oracle source code files.
Friend's I'm working upon searching in maps, here i have string in my array,when
I'm searching for some ready-made solution for working with nested sets with PHP and
I m using UISearchBar,and searching is working perfectly but after search clicking on cancel
After searching a lot around, I decided to post this matter here. I am

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.