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
- Why have on every line
- How to check if woocommerce is activated in theme
- Function to return true if current page has child pages
- WordPress Themes and PHP unit
- How to determine if WP_DEBUG is enabled? [duplicate]
- PHP unit testing WordPress?
- Proper use of Output Buffer
- Include a external PHP file into a WordPress Custom Template
- List of all theme customizer control types?
- How to correctly submit a search form and display the result in an independent page
- Need help setting default setting value for radio button in theme customizer
- Get author full name
- Genesis – Customize search form
- Is having multiple theme customizers for different pages possible?
- How to export/import theme customizer settings?
- Remove Customize Background and Header from Appearance admin menu without CSS or JS
- How to remove hardcoded characters from playlists?
- function_exists call in function.php
- How to exclude pages from the search results
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- Debugging an error: wp_enqueue_style was called incorrectly
- Conditionally loading JavaScript based on the Advanced Custom Fields in the post
- reason of splitting theme files to multiple files
- Modifying widget search box
- How to get the registered sidebar’s name by its id?
- is there a simple way to list every templates / php files used to generate a specific page?
- Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’
- Dynamically change feature image in customiser
- One button to change all settings in theme customizer?
- Rewriting search and pagination base
- Easy way to process search results before displaying
- How to find objects by terms
- Custom HTML structure in wp_list_categories
- How to create a WP_Query to search the Title or Tag?
- Guidance with The Loop for CMS
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- How to use copy() function and paste file in /wp-content/themes directory
- How can i display 3 post types in same page?
- Why isn’t my if/elseif/else working correctly here?
- How to use SRCSET with get_the_post_thumbnail()?
- Design view breaking on Pages
- Dynamically loaded Theme components based on Customizer Settings values : changes not appearing in Customizer preview – (Workaround found)
- How can I add a class to a single menu item?
- Multiple do_shortcode($content) within one shortcode
- How to block specific keywords from searching on WordPress?
- List authors with posts in a category
- Understanding WordPress child theme custom JS loading
- How can I loop into two different DIVS without repeating the DIVs
- Removing unnecessary wordpress files
- Remove css styles from specific page
- Use different javascript files for each page on website
- WordPress loop specific thumbnail size
- Is the regular ajax request method safe or I should use admin-ajax.php?
- How do I get images (with a thumbnail preview) to show in search results?
- Show different Customizer Settings on Page-Tamplates
- How to get custom image size for image uploaded in Customizer
- Passing array in add_option()
- do not show web page section when using advanced custom fields pro
- Is it possible to use the featured image of a page as a css background without inlining?
- PHP Customization: Taxonomies and Queries, why? [closed]
- I think emoji are killing my WordPress site… How can I debug?
- Widgets not showing in my custom theme
- How do I list the_tags() into HTML data-attribute
- How do I translate this string – PHP syntax question
- Site Health : An active PHP session was detected
- Switching between custom templates in a post type of the admin menu
- Enhanced WordPress Search
- Am I not understanding plugins?
- Using Font Awesome as post thumbnail
- Can I change a variable in a content part while calling it?
- How to make thumbnail image fit into a div where image dimentions are completely different?
- How do I dynamically generate args for wp_query?
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- Custom Logo URL | Help me print the URL of the custom logo I inserted into my theme
- How to display recent posts on home page with custom HTML
- Add relevant tag to search results
- Remove annoying WP Adminbar CSS
- What is the fastest way to load PHP functions that are only used in one theme template?
- My Own layout in WooCommerce pages [closed]
- Differences when using the the_time and the_date functions
- Exclude posts from homepage having a specified tag
- Can I use HTTP POSTs? Is there a better alternative?
- Why is this Ajax not working?
- How do I access the media settings
- How do themes render caption texts in extended markup (e.g. “wp-caption” paragraphs)
- Changing the template hierarchy
- using add_action for a header hook that has an additional parameter
- custom shortcode will not display the wrapped content
- Use wp_get_recent_posts with search term
- If search results empty then execute certain code
- Can’t load WP function into external function
- Custom category code not showing all posts
- Count the number of times the search form template gets included on a page
- Displaying theme options in css
- max_input_vars: how many am I using?