Hm, I’m not sure, but your use of have_posts
may be problematic.
Note the codex states “As a side effect, have_posts starts, steps through, or resets The Loop.”.
High up in your code you have
<?php if ( have_posts() ) : ?>
<?php if ( have_posts() ) : the_post(); ?>
This may be causing unexpected results by messing with the loop.
EDIT
I think you’re getting ‘correct’ results for ‘Shortcodes’ (in your example) because ‘Shortcodes’ gets multiple hits. ‘Search’, however, has only one hit, and that hit is being looped over in your header, after which the loop is spent.
So, you need to reset the loop after running have_posts()
, with
rewind_posts()
.
Related Posts:
- Adjust the results quantity for Search Results page pagination
- Search form does not work in my website
- Search only working on front page (index) , not working on other pages
- Search.php gets metadata from first post
- WordPress Themes and PHP unit
- Need help setting default setting value for radio button in theme customizer
- Remove Customize Background and Header from Appearance admin menu without CSS or JS
- Modifying widget search box
- Dynamically change feature image in customiser
- Design view breaking on Pages
- How do I get images (with a thumbnail preview) to show in search results?
- Passing array in add_option()
- Is it possible to use the featured image of a page as a css background without inlining?
- How do I translate this string – PHP syntax question
- Site Health : An active PHP session was detected
- How to make thumbnail image fit into a div where image dimentions are completely different?
- How do I dynamically generate args for wp_query?
- How to display recent posts on home page with custom HTML
- Add relevant tag to search results
- using add_action for a header hook that has an additional parameter
- Use wp_get_recent_posts with search term
- have_posts() execution failure
- Can’t search posts using WP_QUERY inside AJAX Function
- Using a `Template Parts` folder instead of an `Includes` folder in a Custom WordPress Theme
- WordPress pagination not working with search page
- Set the checkbox as checked by default at options page
- Input type search in Menu
- what is the best practice to add new field to an api route
- Grab posts by multiple categories
- populate form fields in a loop with ajax
- Error in custom php function doesn’t exist
- Customizer: active_callback and sanitize_callback incompatibility?
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Autocomplete search box
- How to disable controls in theme customizer?
- Can anyone offer any help with this function?
- How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
- What does this mean in wordpress? Easy question
- Use Tags to initiate Search
- Show About and Contact Us page when they’re clicked in the top menu.
- Is There A Way To Make Theme Files Accept Shortcodes?
- Theme’s Options Page included with require_once *.php in functions.php not visible anymore
- WordPress import media error
- Hide Heading if ACF Field is empty
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- How to add the sidebar to all the pages except the home page? [closed]
- Header not properly displaying on archive.php
- How do I get the content excerpt of the recent post?
- Save Custom CSS file in the upload folder dynamically?
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Getting posts to exclude from array
- home.php show blog posts as grid view
- Custom post type permalinks do not appear using the link functions
- Is there a name for trivial WP PHP files like functions.php, archive php entry.php, page.php and so forth?
- Using bloginfo and divs inside a php file
- Unable to access WordPress functions from functions.php
- Get css class of menu item in custom menu structure
- How to organize functions.php content
- Why when I create a new post I found 2 record related to this post into the posts database table?
- pass html code to worpdress
- Commas in Tag Cloud
- Trying to change featured image from 180×180 to full width on home page
- Remove the Tag from wp_nav_menu
- security concerns if using html data-* attribute for l10n?
- Free search and custom taxonomy query not providing the same result
- Getting text from custom field from customizer
- WordPress navigation wont appear with wp_head
- How do you create a custom category widget that you can style?
- Replace a single variable with add_filter
- How to change basename url for wp-admin?
- url not using query string no longer working
- meta_query search names when they have middle initials
- Not able to remove caption shortcode from the content
- Limit Search to Product Pages only unless I’m on Blogpage or Blogposts
- Weird fonts showing which are coming from database
- Problem with displaying CSS Stylesheets – Am I adding them correctly in my wordpress child theme?
- require get_template_directory() . ‘path/to-my/file.php’ BREAKS customize > themes functionality
- How to have different headers.php files based on the display page
- What is the correct way to search 3 custom fields only in WordPress?
- alternate left – right content inside the loop
- Proper use of Output Buffer for a whole php clas
- CSS loading as empty file in Custom Theme
- Woocommerce variable products are being added to the card on the homepage (ajax)
- How can I customize a WordPress theme before it’s downloaded?
- I want different post-thumbnail size depending on media size
- Create a custom theme-specific page, invisible in the admin-panel?
- Trying send mail from Theme page
- A Customizer checkbox control that sets the setting to “” or to “blank” and show() or hide() a color control
- Make the text field in search form optional
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- Shortcode working in page.php but not in category.php in wordpress
- Adding a Sub Menu Options Page WP Backend Menu. Whats wrong with my code?
- How to strip/remove all blank spaces at the beginning/end of a search string
- How can a ‘scripts’ directory be hooked into wp_head();?
- WP and Laravel integration (Updated) [closed]
- paginate_links() returns NULL instead of the pagination links, but pagination is actually happening
- PHP warning: Undefined array key 2 in feed.php
- Variable ++ in query loop
- Dynamically added text at bottom of article – non searchable by PHP code
- functions.php doesn’t load all custom theme assets