functions.php
<?php
add_filter( 'posts_where', 'title_like_posts_where', 10, 2 );
function title_like_posts_where( $where, $wp_query ) {
global $wpdb;
if ( $post_title_like = $wp_query->get( 'post_title_like' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( $wpdb->esc_like( $post_title_like ) ) . '%\'';
}
return $where;
}
?>
Then:
$args = array(
'post_title_like' => $str
);
$res = new WP_Query($args);
Related Posts:
- How to Get All Posts with any post status?
- How can i get count from query post
- How to set posts per page using WP_Query()
- query_posts() in function makes global $wp_query out of sync?
- Problem with ‘post__not_in’
- Sort posts alphabetically by custom field value, insert divider between different letters
- Is it better practice to use query_posts, WP_Query, or get_posts to create various custom loops within a Page?
- Custom Post Type “Event”: chronological list of recurring events
- query_posts doesn’t order by title
- Total Count of Posts NOT in Selected Categories?
- Order posts using a custom array
- Tricky WP Query
- WordPress pagination showing same posts on each page
- Search breaks when querying main loop for category
- Using ajax with paging and a custom sub-query
- Custom loops, sticky posts, and pagination nightmare
- get_the_title outputs title until spacing; it does not get full length of title
- odd behaviours from template tags
- Having an issue doing a WP_Query with post_content and category__and
- Custom query looking at multiple custom fields and properly sorting
- Pre-existing arguments when using queries
- How to refine WP-Query with further criteria
- Run second query on page based on author of the first query
- Query Posts (post meta)
- Wp get all the sub pages of the parent using wp query
- Filtering posts by post meta data
- How to query_posts using meta_query to orderby meta_key AND have a secondary sort by date?
- Using WordPress to make a “Product Search” type navigation drilldown
- Help to condense/optimize some working code
- How to make “sticky” pages (and query by them)
- Build a content and excerpt grid loop with paging and options for # of posts
- Get posts by meta data OR title
- Using is_main_query to select custom post type on certain page
- WP_Query ordered by custom field that is a date string?
- using post__in allow duplicate post id
- Display Posts by modifying the where clause only for my query
- search query within custom taxonomy term, post title and meta field
- Use union/intersection query_posts variables in uri request parameter form?
- Custom query with query_posts doesn’t show post without certain meta_key
- query posts in wordpress
- How to query ‘posts_per_page’ to display a different blog posts index template?
- Advanced Tax Query
- Post count per (day/month/year) since blog began
- Dynamically excluding current page id
- How do i paginate query_posts with numeric pagination?
- How can I pick a single post from the latest 3?
- Static Front-Page Excerpts
- Query with custom taxonomy not working
- Improving WP_Query for performance when random posts are ordered
- Query posts by specific word on title
- Sorting multiple custom post types without a meta key/value pair by sort order
- tax_query operator woes
- cannot get multiple loops using tax_query
- How can i display the posts per week in a particular month?
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Custom Query num_rows returns wrong amount
- Fetch Record based on meta key dates
- add active class based on permalink and url
- ACF Query meta_values don’t work with ‘offset’
- Filtering out child category posts from parent category archive not working
- How to retrieve an array of post IDs by a particular value stored in a custom meta’s array
- define orderby URL with meta_key=post_views_count
- Query_posts and attachments
- Querying posts only if the current page is not paged?
- Nested WP_Query breaking loop
- Advanced WP Query and/or
- how to store wordpress loop in array?
- Query for first 3 posts to change the look and feel
- Exclude posts by post meta value
- meta tag placement for google verification
- Frontend form with multiple posts
- How can I comment comma-separated array values?
- Way to cache a query for 24 hrs
- 2 queries with counters
- WordPress query portfolio posts
- Remove Post if Advanced Custom Field is checked to fix paging
- Multiple Query_Posts
- Display 3 posts with different HTML markup using a loop
- Meta query stopped working
- Sticky posts don’t show up first in custom loop
- Want Page Descendants when using query_posts post_parent or child_of
- Querying a query
- How do I query based on the modified date?
- how to display posts content on the custom css popup by clicking on each title on the sidebar?
- Custom query for custom post type not getting correct post ID
- Show 5 posts and than 3 posts offset with pagination
- Merge two queries and remove duplicate
- Query only title/field/featured media of posts [closed]
- Create a hierarchical loop at predefined markup requirements
- Imported Content Doesnt Show Up On Frontend
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- Remove duplicated posts in the loop if post has more than one category
- query_posts not working after wordpress 3.7 update
- Is that the query_posts() the real criminal here?
- query_posts and sub pages?
- prevent display duplicate titles on main page
- Pagination in category.php not functioning
- Lots of SQL queries
- WordPress pagination returns the same posts
- Assign a tag to custom post type using a query