The problem is here:
if( get_post_type()=='page' || is_single() ){
echo '<h1 class="h2">'. $post->post_title .'</h1>';
}
get_post_type() is using the global $post, which will contain the first post in your result set. If this is a page, then your other conditions will never be tested and you’ll never reach the is_search() test.
Use is_page() instead:
if( is_page() || is_single() ){
echo '<h1 class="h2">'. wp_title( '', false ) .'</h1>';
}
or, use is_singular(), which will be true for page, post, or attachment, or any singular post type:
if( is_singular() ){
echo '<h1 class="h2">'. wp_title( '', false ) .'</h1>';
}
Related Posts:
- WP Query Args – Title or Taxonomy Value
- Can I force WP_Query to return no results?
- Post_count only shows the number of results per page
- WP Query where title begins with a specific letter
- Search custom taxonomy term by name
- Order Search Results Page by meta_value If no Value Return Remaining Results
- Tracing the life of a query
- Want to redirect if search query match exact title of any post
- Pagination not working for Custom search form & custom result template
- How to support multiple search terms query within one process?
- Pagination broken when merging search results with additional WP_Query
- Custom search form with empty parameters
- How to search by title or tags exclusively?
- WordPress search exact match
- Pagination wont work with search results template [duplicate]
- How do I search WordPress by different fields without a plugin?
- Multiple keyword search
- Using next/previous_posts_link with customised search
- WordPress custom search form with pre_get_posts not work
- Search – Ajax – Alter Query Parameters with Pagination
- Add custom search results to main WP search [duplicate]
- Multiple search queries on one page
- posts order by title second word
- tax_query shows no results if nothing is selected
- Searching through different categories on different pages code is not working
- WP Query search for attachments and their exact title
- WP_Query’s “request” SQL Query
- Including only current user’s posts in search
- Wp query orderby ‘title’ doesn’t work
- is_search was called incorrectly
- How do I search inside specific taxonomies in WordPress
- Modifying the Search Results
- Custom category search box for WordPress
- Refine search results using WP_Query
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- Search Posts with Custom Fields as query
- Complex date range with WP_Query and BETWEEN
- Creating a custom search for a specific post type
- Custom Search Result Page displaying only 1 result.
- How to loop for every result found in the_content() when using the search query?
- Assigning a meta_query value based on regexp to wp_query fails
- showing all search result in one template
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- Is there any advantage of using default WordPress Search instead of creating a custom one?
- WP_Query Not Recognizing Taxonomy Parameter in Custom Search
- Search pages that are a child of the current page
- Include tags in WP_Query
- Search for multiple tags?
- Custom Search Not Consistent with Results
- wp_query ‘s’, search filter with pagination is not working
- Editing the default wordpress search
- How to use wp_query to post count by search term > group post count by date > convert to json. (ex. result 12-21-2020 – 343)
- Multiple Search Terms WP_Query
- Extend product search with meta in WooCommerce
- Display filtered results into custom page
- WordPress pagination not working on template search.php
- Cutom wp_query for geolocation search, pagination not working
- wordpress search word, “hello world” ===> ‘hello+world’ ===> ‘hello’, ‘world’
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- query_vars overriding WP_Query args
- Query with search and subscribers only output
- how can I override The Events Calendar query modifications?
- Search by post id in a specific page then auto-redirect to searched post
- Search for “2nd” also returns “22nd” in wp_query
- How to make search for posts using get method?
- Categorising search results based on Custom Fields
- How to output the title of the blogs home page
- Add filter post_where and passing post_type argument
- using pre_get_posts for search results not found
- Search posts missing a particular custom field
- How do I get my custom query to work with search results after the first page?
- Modify Search Query if original Query gave no results
- Include post content of linked posts in search
- Replacing search results with custom external query
- Prevent author bio page from showing in search results
- How do I amend wp_query before it is run/executed?
- wp_query search not taking keywords with together for multiple words
- Wildcard search in WP Query
- Get a list of posts by specific category
- WordPress Custom Search Form Displaying Unexpected Results
- Search Page Returns Nothing
- Redirect Search to Form When No Product Results Are Found
- How to properly use AND / OR in custom search
- How to avoid bypass of search bar rules?
- Hide products in uncategorized category from search results
- Issues with search after added meta_query
- How do you determine if a result in a search query is a post or a page?
- Slow Query On Search
- Sorting search results with custom dropdown
- wp_query show all values
- change posts_orderby of the callback wp_query?
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- WP_Query by keyword OR post tag
- How to restrict search on a certain page to only return results against custom taxonomies?
- Filter out a meta key in the Search results page with two CPT
- Query by key or author
- Ignore image urls in wp_query search
- Search.php – return number of results but cannot loop through
- Can I make a search query which includes a space?
- How to filter a static post page with ajax and $wp_query