What you’re trying to achieve is a LIKE
query. But you’re using the compare
arguments that are only present for meta_query
arguments. You need to utilize a filter like the following:
add_filter( 'posts_where', 'wpse120358TitleLike', 10, 2 );
function wpse120358TitleLike( $where, &$wp_query )
{
global $wpdb;
if (
'post' === $wp_query->get( 'post_type' )
AND $wp_query->get( 'name' )
// add further restriction arguments here:
// AND ...
)
{
$where .= $wpdb->prepare(
' AND %s LIKE %s',
"{$wpdb->posts}.post_title",
'%'.like_escape( $wp_query->get( 'name' ) ).'%'
);
}
return $where;
}
Note that this is not a tested script. It’s meant as a guideline that can be built upon.
Related Posts:
- Meta_query compare operator explanation
- Exclude post ID from wp_query
- Can I force WP_Query to return no results?
- paginate_links() adds empty href to first page and previous link
- Get array of posts from the current archive page loop
- Get posts by menu ID
- Custom query incorrectly returning everything [closed]
- Last post ordered by publish date using WP_Query on front page
- Meta Query with date and time on the same Day before given time
- In loop: posts have thumbnail AND other variables
- How to grab metabox value in wp_query meta_query key
- Add and in the header while looping over custom query in page template
- Stop all SQL_CALC_FOUND_ROWS wordpress queries
- Single page theme
- Pagination not working on static page
- How can I create a WP_Query that returns posts where one meta_value
- Get posts from the Main site to sub site – WordPress MultiSites Network
- WordPress pagination link always leads to home page
- Query posts with more than 20 comments
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- Get array of current post term ID’s
- Implementing an OR statement to wordpress wp_query
- How can i simulate “taxonomy__in” in query?
- query_posts: how to show all ‘meta_value’ containing a specific word?
- How to show subcategories using loop?
- Minimize database queries to user tables?
- Get all products which have both product category
- How to make Meta Query case sensitive?
- Populate tax_query terms parameter with post term
- Orderby the sum of several numeric custom meta fields
- unable to retrive parent page information
- Site not getting correct featured image from my query
- Fastest way of counting posts of a custom post type in a specific taxonomy term?
- wp_query ‘s’, search filter with pagination is not working
- Use more than one query, but prevent duplicates – at scale!
- Why is wp_query causing an uncaught error to is_user_logged_in() not defined?
- Modify wp-query and sort by post meta key
- How to display an other custom post type in a different custom post type’s archive?
- Replacing raw database query to WP_Query
- Stale $GLOBALS[‘post’] after custom WP_Query empty result set bothers my template, whose fault is this?
- How to alter local query, not main query [duplicate]
- WP CLI can’t delete plugin related table
- Inserting HTML to close and open divs in WP_Query loops
- Change query from cat id to slug or name?
- Query only the posts with a post format of “audio”
- Display Current Post’s Position in Custom Taxonomy
- Using Wp_Query without the loop?
- WP Query with multiple tags by get the tags
- Custom WP_Query id
- Woocommerce pagination and result count after custom loop
- Parent and child categories
- Set post number to single posts
- Orderby custom meta returns random order
- Include latest author posts with pagination in single template?
- How to querry for an item that saved in an array?
- get_post() is not returning correct value
- Intiger meta value with ‘>=’ returns posts with lower value
- Update query for wp_posts and wp_postmeta
- How to print term name inside wp post loop
- CPT category post/content is not showing on my page, Please review my coede
- Grabbing taxonomy terms and inserting them into an array
- WP_Query with page_ids in arguments without a result
- Phpmyadmin – post editing
- Query not sorting DESC
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Filter products on category AND tag
- meta_query – check for multiple meta values in key which holds an array of values
- How to sort wordpress posts already selected by WP_QUERY
- How do I stop the same post showing multiple times in a archive?
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- SEARCH QUERY PLEASE HELP | call_user_func_array() expects parameter 1 to be a valid callback php
- WP_Query on custom key and value
- Set “editor” role to existing user
- how to get wp_query posts only first letter of alphabet A?
- How to mix two orderby-parameters into one ordered result
- Custom Post Type WP_Query with filters and search
- Merge wp-query and get_users
- WP_Query how to add a thumbnail to the first post from the last 5 posts?
- Get posts by similar names and categories
- Query by meta value (add a dropdown of all values)
- WP Query issue for multiple values
- Calling a function with WP_Query only ever brings the first result
- get last child post by wp_query
- WP_Query don’t working with fixed post_id and term_taxonomy
- How To Query All Attachment Images Found In Post Galleries
- WordPress meta_query not working
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Using orderby with 2 meta keys
- $wp_query when new WP_Query
- Query to get all the posts of more than 2 meta_value having same meta_key?
- Divide WP_Query posts by date & post type
- Unable to pass variable
- WP Query get posts by specific author IDs if one of several logged in authors
- Edit WordPress loop, taxonomies, & filter
- WordPress website links redirect to homepage
- How to display posts from a specific term first then another posts from another terms using tax_query
- Using WP Query, I want to include all posts in category 1 as long as they are not also in category 2
- Prevent URL Parameter Affecting other WP Query
- Sort by multiple columns using get_posts
- WP_Query filter Posts by timestamp event (range start and end) and by month (next 12 month)