Here’s one suggested high level approach to get the desired effect.
-
Rather than perform all your operations in one big while loop in your searchresults.php, try:
- establishing three arrays corresponding to each type- you can do this in one while loop.
- then sort each array as needed (refer to PHP’s Sorting Arrays documentation for the various ways to sort a multidimensional array)
- then output the section heading and loop through your teasers of posts for each type.
-
Alternatively, in your
group_by_post_type
function’sif
statement, you can perform steps 1 & 2 above, and then merge the arrays, returning the merged result and keeping your searchresults.php pretty much intact as you’ve posted it.
Related Posts:
- Search everything (posts, pages, tags, cpt, meta)
- WooCommerce product search titles only
- How to order separated Custom Post Search results
- Prevent A Specific Custom Post Type Showing In WP Search Results Page
- How to sort custom post’s category by id from the theme’s function.php?
- AJAX search on post pages by custom post type
- How can I change the admin search posts fields?
- Development of a WordPress Search Plugin – Best Practices
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- Simple way to search custom-post types only
- Pushing a custom post type to the top of the search results
- expire wordpress user posts
- Forcing all posts associated with a custom post type to be private
- Detect meta value changes when post is updated (post_updated)
- filter search result with custom post type meta key
- How to Removing fields from the Media Uploader/Gallery on a Custom Post Type Edit Page
- Compare 3 custom fields and sort by oldest
- Best way to style first post differently?
- if && problems with transition_post_status
- Search Post Title Only [duplicate]
- Beginner question: Accessing functions.php through admin web interface in order to import custom post types?
- Customize Search Results for Custom Post Type
- Post the content of a specific “Custom Post Type” post within a post using a shortcode
- multiple search forms and search results
- Need functionality with all post list available at edit.php
- Custom Fields vs Separate Table
- Remove default post types on all sites except primary blog. WPMU
- How to search map address in custom post type?
- Custom Post Types relationships
- Custom Search for Drafts in Custom Post Type
- Copy custom field value to post title
- Insert HTML inside link in a walker
- Remove standard meta boxes from custom taxonomy
- What’s the difference between same wp functions get_posts(); functions in different form?
- Show category ID on custom post type
- custom post type Search returns No Results in admin panel
- How to stick custom post at the top in search results
- filter custom post type by meta key in dashboard
- Can I search only some of the fields of a custom post type?
- Change CPT archive title
- AJAX load more for different custom post type loops
- I need to add endpoint for wordpress categories
- How to do WP_Query with two meta fields with orderby clause
- Cannot save CPT meta box
- next_/previous_post_link() `in_same_category` appears to fail when true
- Want to be able to sign up subscribers as authors
- Advanced search form with filters for custom taxonomies
- Warning: Invalid argument supplied for foreach() [closed]
- Custom post type isn’t working
- categories should be available across all custom post types
- Search one custom post type ONLY, disable “all posts”
- Custom Post Type & Custom Menu Walker to append custom class for active post types
- Custom post type sorting: alphabetical order
- custom post for slider
- Excerpt function for any content
- Page Template Dropdown For Custom Post Types
- providing access to post_id or post inside functions.php
- Pagination on search results page
- post_content is stripping HTML when adding a new post? [closed]
- Best way to create a search for custom post type by custom field values
- Function to limit number of custom post types on homepage – TwentyTen
- Multi Parameter search with custom post type category and tag
- Excerpt length: get first paragraph
- display custom post on separate page
- Post type Echo code is repeating on homepage
- Redirecting search to specific templates with $_GET[“post_type”]
- new post-type how do i retain the plugins on my sidebar?
- Search custom type post
- Custom Post Type Dashboard Tab not displaying any posts
- Title and URL Error in Breadcrumb Navigation for Custom Post Types
- Display Parent-Child Posts in specific order by comparing IDs in array
- Assigning categories to custom post types via a front-end form; only works for native post type
- Order posts alphabetically with numbers but some of the posts has numbers in the title
- How to order taxonomy terms by most recent post?
- Creating a custom WP query for a Custom Post Type
- WP_List_Table Inside Metabox Not Working on Clicking Search Button
- SEARCH QUERIES – REVERSE OUTPUT
- From CPT Custom Loop into Shortcode?
- search results to show individual ACF fields from inside custom posts
- post_type incorrect for custom post type
- Live search by custom tag
- How to order multiple custom post types with same taxonomy by date
- how to create custom taxonomy drop downs for parents and child
- How to assign post to category
- If thumbnail image else post title
- $_SESSION Not working after X amount of page views
- Different Configuration for the_excerpt()
- WordPress page not showing up – replaced with last 10 posts?
- How to mark posts as visited
- WP Query with multiple post types ordered by custom meta date then published date
- can’t see categories in appearance-menu-categories
- Custom post order when using OR relation
- Extensive search filtering and results->PDF in the front-end
- Advanced search form with filters for custom taxonomies and custom fields
- Searching for a single custom post type, buddypress
- How do I do this?: If custom post type exists, echo it, else do not
- WordPress search results
- Drop Down Filter with CPT as Options for Search Form
- Query order by meta value force specific tag first
- Is it possible to use a post name in a custom post slug?