Probably the simplest approach is to combine the category query with a search query (untested):
$cat_query = new WP_Query( array(
'cat' => $cat_id,
'post__not_in' => array( get_the_ID() ),
'no_found_rows' => false,
'posts_per_page' => 6,
) );
$title_query = new WP_Query( array(
'post__not_in' => array( get_the_ID() ),
's' => get_the_title(),
'no_found_rows' => false,
'posts_per_page' => 6,
) );
$related_posts = array_merge( $cat_query->posts, $title_query->posts );
// Need to sort the posts so they're not grouped.
$dates = array_column( $related_posts, 'post_date' );
$related_posts = array_multisort( $related_posts, $dates, SORT_NATURAL );
// Limit to six posts.
$related_posts = array_slice( $related_posts, 0, 6 );
Related Posts:
- Is There a Difference Between Taxonomies and Categories?
- WooCommerce: List All Categories
- Get rid of WordPress category, tag and author archives?
- How can I hide a category from Contributors in the edit/add new post screen?
- Category page doesn’t use category.php, instead it redirects to homepage
- Multiple post categories – single permalink
- Wrap Post count in a span
- wp_nav_menu not appearing for a couple pages
- How to exclude uncategorized from permalink structure /%category%/%postname%/
- Create product category and keyword search form in woocommerce? [closed]
- Trash bin for categories
- Saving two categories from two dropdowns in front end posting form
- Display one category in one page
- How would you create a “weekly” archive?
- Exclude most recent posts from specific category in wp_query()
- Display all posts with same title
- Show children of top level category only
- is_archive() content being shown instead of is_category()
- Check is category parent or not from its ID
- wp_list_categories to show list of categories and the description
- How to display a description of a given category from a custom taxonomy
- Add custom taxonomy under the category title
- Retrieve all posts within tag OR category?
- How to modify category.php to list posts alphabetically?
- Include template before a loop
- How to customize tag and category post listings to show introductory content?
- Sorting posts by season
- Include posts from feature category in pre_get_posts
- Create blog page only to see one category
- Looking for the best solution to build this Blog structure? Picture attached?
- How Can I Display Categories Description
- Specified number of categoy posts not showing correctly
- Display Slug instead of Name
- Set Current Category to Active in category.php
- Filtering multiple categories via the URL
- How to hide category description in the subpages? [closed]
- Remove sub-menu item from admin menu
- WordPress query via checkbox form
- Multiple categories with common subcategories
- Counter in loop in foreach
- How to limit number of attachments
- Show category name and new articles and display page numbers. What function to use
- Add child category to parent on post creation and save
- wp_list_categories in in nav_menu
- WordPress Post # of # filtered by category slug
- wordpress multisite… collect all posts on main blog – exclude category?
- Sub category templates
- How to use an array of categories as a dropdown?
- ACF add custom fields to categories and display
- How to put an array in is_category
- How to add custom color fields to the category edit page?
- How to create a custom categories page
- Select posts from Category
- Target a specific category from a custom taxonomy?
- How to modify the output of wp_terms_checklist when used within the built-in category metabox on edit posts?
- Searching for a category returns nothing if category is empty
- Category page returns 404 error
- How to get nav to show current_page_parent class when on regular post (not blog), differentiated by category
- How to exclude posts from category posts count
- Random category with recent post title and thumbnail
- I would like to feature a tip on the homepage
- Redirect depending on category chosen
- Problem: retrieving parent category’s first post
- Category URL Management
- How do I export the headlines of all the blog posts in a single category?
- how can we bring category metabox to Media Library/Upload New Media Page
- How can I display a list of categories of my posts
- Category post count is not correct
- 404 on category URL
- Problem creating wp categories
- List of post categories only associated to another custom taxonomy
- How to add commentary types or category for a post
- List all categories and count number of posts within based on custom date
- Pagination for custom categories template
- Category URL’s 404 after setting category base to ‘.’
- How to allow each editors to only edit certain categories?
- Bulk assign posts to a category using SQL (MySQL)
- sort post category listing
- Excluding particular category from displaying in specified areas
- Query post if has two of the categories
- Display Category description
- Display all posts from specific category
- How to use categories, sub-categories and customize navigation view
- Hide empty category on woocommerce
- How to apply wordpress ‘with_front’ = false for categories?
- Custom Category Archive Pages
- Adding a category view to a page
- make categories editor unchangeble for my post_type
- same permalink for parent category and child category
- How to get multiple loop in category.php, my scripts becomes madness
- What approach should I take for this URL structure?
- Custom loop by url
- how to display page title only for child category pages
- Chained drop-down menu for custom taxonomy using chained.js
- How to display the posts belonging to a paticular category
- WordPress 3.5 how to determine if user is on category listing or category edit screen?
- Javascript code for Category
- Display only one level subcategory in wordpress
- How Do I Add HTML Support to the Additional Category Description Field?
- List the category tree of all the product_cat categories