You can use WP_query()
to narrow down the results of your search:
<?php $args = array(
's' => $_GET['s'],
'post_type' => array( 'post', 'page' ),
'post_status' => 'publish',
'category_name' => 'music',
'posts_per_page' => -1
);
$custom_search = new WP_Query( $args );
if ( $custom_search->have_posts() ) {
while ( $custom_search->have_posts() ) : $custom_search->the_post(); ?>
<div class="entry-content">
<h2 class="title"><a href="https://wordpress.stackexchange.com/questions/262512/<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
</div>
<?php endwhile;
} else { ?>
<h2>Your search didn't return any results.</h2>
<?php } ?>
Related Posts:
- exclude category from get_posts?
- WordPress Multiple Category Search
- Exclude the category from the WordPress loop
- Exclude certain category from latest updates
- Exclude categories from search query
- Exclude categories from Loop, queries, widgets, post navigation
- How to search for categories and/or tags?
- List posts by category exclude current post
- wp_list_categories exclude not working
- Sticky posts on home page, search, tag and archives without plugin
- Create product category and keyword search form in woocommerce? [closed]
- Excluding a category from next and previous post links
- Exclude Category From Home Page, Display Posts on It’s Own Page?
- How to exclude categories from recent posts, recent comments & category widgets?
- Custom Query to search through categories
- Exclude a category from the filed under list only on some templates
- How to show empty category in admin menus search
- How to select product category while adding new product in woocommerce? [closed]
- How do I get the total number of categories in a list of search results?
- Category Search functionality on category metabox (wordpress admin)
- Search by word, category, tag, author
- Filtering search results
- Help with multiple dropdown tags search
- How to exclude posts from a category when using this particular format
- Exclude category from Tag Template
- exclude post from displaying in loop if it is in a category, but not in many categories
- Multiple Category Search
- get_the_category and echo out link to child-most/deepest category
- Search Posts / Pages with multiple options?
- Exclude Posts From Specific Category from Next and Previous post links
- How to query post like normal search would do. within search.php page
- Query Posts Exclude Entire Category
- exclude categories from search results
- Exclude category from fucntion
- WordPress search only showing a few posts
- Site search needs to find posts for category topic AND Tag or keyword thats not in the post
- Search in custom post type AND in pages with category
- WordPress category widget only show categories with children
- Select posts by name and category per REST API
- How do I toggle pagination on/off in search results and category listings via a link?
- Refine/Filter the Search Results by Category
- Show matching categories in search page
- Keyword search in multiple categories
- wp_list_pages() exclude category
- Get URL Category Name By ID
- Exclude category from query
- Functions.php: Exclude Category from “Blog”
- Group search results by category
- Woocommerce filter function not updating
- Woocommerce search form with category select
- wp_list_categories not excluing multiple ids
- Using if statement in index.php instead of creating separate template files
- How to exclude posts from category posts count
- Exclude category from foreach loop
- Have posts that belong to multiple categories, exclude some categories from homepage
- Exclude all subcategories in the_category (post)
- I need to exclude from a query a category and a few custom taxonomies
- Exclude categories by ID
- Search form options group categories
- Homepage custom recent news
- Exclude the category in WordPress
- How can I exclude a category from the main loop with the category name & not ID?
- User level categories
- Exclude category from drop down list form
- Show Posts via cat+cat in URL that are in both Categories doesn’t work
- exclude certain categories form archive widget
- WordPress Default Category and Custom Taxonomy Selected Attribute not Working After Searched in wp_dropdown_categories Array
- Automatically adding tags and categories into Post Excerpt for searching
- Return all Tags and Categories in Separate List
- How to remove an item from a custom Walker_Nav_Menu
- Exclude a category and post_type from wp_query
- How can I exclude a particular category from my WordPress Page 1 and Page 2?
- Search Replace Database ONLY for posts of certain category?
- Exclude category from WP_Query args not working
- Displaying Category in sidebar post widget but not in the loop on home
- Search by tag, category and author without plugin
- Issue with WordPress category search
- get_terms sort order with child categories of varying depth
- 404 error when i try to search by category or by tag
- Make related posts display first in search result
- A search box for all sites – Multisite
- Category menu that filters out empty categories
- Several loop in search result
- Search functionality with multiple categories
- Problems with explode [closed]
- Exclude Category From Home Page, Display Posts on It’s Own Page?
- How to have a category not show up in query post with page panigation?
- Customize category query in widget
- Query posts that have all the specified tags
- Call function on a single page
- Excluding cateory not working on my site. how to solve this? [closed]
- Display category tree of a post in search results
- How to define category ID in an array?
- Remove “All categories” from searchbar dropdown
- Display different sidebar based on search results from one category
- How to create a widgetized sidebar for every category dynamically?
- Resolved – category-slug.php not working after wordpress migration
- editing fonts of category links from the_category() funtion
- Displaying list of subcategories and not parent category
- How can I get this code to only output one link?