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?
- How to customize a permalink (URL) structure?
- custom post type Search returns No Results in admin panel
- Rewrite and custom post type: order by custom field not working
- Custom Post Type with Templates using Meta Boxes?
- How to set order for a custom post type
- Search Custom Post Type & Taxonomies
- Previous/Next Link by Meta Value in CPT
- Can I list a custom post type within another custom post type in the admin area?
- Change custom post type slug from plugin options
- Multiple meta_values in the pre_get_posts filter?
- Wp_query: sort by PHP variable
- Allow user to set custom order to a list of custom taxonomies?
- search also in taxonomy, tags and custom fields
- Custom post type search using $_SESSION and pre_get_posts
- Can’t edit custom post type
- 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?
- Custom Post Type And “fopen”
- Filter custom posts using auto populated dropdown selectors
- Set URL link to featured image of custom post type
- Make parts of your wordpress website completely built with data from external APIs?
- Change CPT archive title
- AJAX load more for different custom post type loops
- PHP variable not regenerating when publishing multiple posts at the same time
- On update or create post redirect to current post position in list
- I need to add endpoint for wordpress categories
- Sort CPT archive by order prevents sorting in admin
- WordPress sort search results by custom order
- How to target a specific custom post type post and its all children and grandchildren?
- Featured image overlay when changing post status
- get_post_meta not working on publishing
- Redirect 404 page with ID in slug to associated page with same ID in slug
- How to do WP_Query with two meta fields with orderby clause
- WordPress wrapped added a span tag to every single p tag
- ACF field key/value to show on taxonomy list
- Re-registering a custom post type not working (not showing up)
- Display featured image from one CPT within another CPT query
- Query taxonomy of taxonomy of custom post type
- Best way to style first post differently?
- How to make custom posts types display when published for the future
- Including metaboxes from custom post types in global search — continued
- Custom post type not showing in search result
- How to rewrite url for any specific taxonomy?
- create a new page from a custom post type similar to an authors page
- CPT archive admin menu label
- Anon function and add_meta_box
- What to and how to proceed with CPT to make DB small and efficient?
- How to order and group custom post type posts by year and month
- Pretty URL for custom search for custom post type
- Order Custom Post Type by Custom Field Value
- Add post location with mile radius allowing search
- Include custom post type content in search
- Get post count for search result based on post type
- Hide a widget inside a div on specific type of post
- Shortcode not working with post counter
- Changing default ‘posts’ parameters with register_post_type_args
- Auto Complete Search
- search suggest – filter post type
- Searching Custom Post Types
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Get the taxonomy of a post hierarchically
- Cannot save CPT meta box
- Change sort order when using ‘orderby’ => ‘type’
- Display Woocommerce Orders for specific author [closed]
- How do i search authors from search form using author’s name
- Allow users to create posts without logging in?
- How to change permalink to include custom post type
- Remotely search WordPress sites using xml-rpc
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Ordering custom post type by multiple custom fields
- Add term to custom post type on draft
- BBPress Search results in WordPress search
- Limit Search to Post Type With Apostrophe return search not found
- How to assign classes to all elements?
- Search filter triggered & sort by custom post type
- Set Custom Post Type in Widget Settings for use in Widget
- next_/previous_post_link() `in_same_category` appears to fail when true
- Displaying and searching Custom Posts
- Search by tag name and category
- Searching Custom Fields
- Want to be able to sign up subscribers as authors
- Advanced search form with filters for custom taxonomies
- dropdowboxes with pre-selected custom fields optios that filters the results according seach needs
- Manage Columns : order by post_parent’s title
- filter search custom field query
- Different results between permalink and query var search
- Order by custom field meta_key date and then by custom file meta_key number
- How to let users choose where to search for posts?
- WordPress Custom Search by post_type
- Include custom taxonomy term in search
- Load scripts based on post type
- Different Category system needed for the Custom Post Type
- Global custom meta box
- Template not working for the custom Post type