I would solve this with a filter on WP_Query
. One that detects an extra query variable and uses that as the prefix of the title.
add_filter( 'posts_where', 'wpse18703_posts_where', 10, 2 );
function wpse18703_posts_where( $where, &$wp_query )
{
global $wpdb;
if ( $wpse18703_title = $wp_query->get( 'wpse18703_title' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( $wpdb->esc_like( $wpse18703_title ) ) . '%\'';
}
return $where;
}
This way you can still call WP_Query
, you just pass the title as the wpse18703_title
argument (or change the name to something shorter).
Related Posts:
- Pagination with custom SQL query
- Whats the difference between post_limits and pre_get_posts?
- Using OR conditions in meta_query for query_posts argument
- Is it possible to wrap Geo Location search around WP_Query?
- Is it possible to select against a post’s parent’s fields with WP_Query?
- Extending WP_Query — Optimise SQL query
- How to filter sql only for a specific post type
- How to make an activities stream mixing posts and comments?
- SQL Statement generated by WP_Query not producing expected results
- What is an efficient way to query based on post_meta?
- SQL query equivalent to WP User Query
- Recommended way to drop a pending query (in pre_get_posts)?
- how to retrieve specific product attribute value in an sql query?
- Filter WordPress posts by between parameter
- SQL User Query by Multiple Roles using PHP
- Advanced WP Query hogs the SQL server
- SELECT * FROM $wpdb->posts WHERE ID > 160
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- Query post with meta_query where date is not in future
- WP User Query get all authors with last name starting with specific letter
- Select from wp_post and multiple meta_value from wp_postmeta
- How to correctly pass values to wpdb->prepare()?
- Sort users by “birthday” using WP_User_Query
- $wpdb select date range of posts
- How To Fix WP Query Returns Results But Shouldn’t?
- List of the years with posts presented
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- Slow WP_Query for custom post type
- Complex WP SQL Query
- Query that loads a custom type AND posts whose ids are not inside those custom types custom fields
- Optional Meta Query
- Sorting events by descending date, and ascending time if multiple events on a date
- Editing the default wordpress search
- WP Query related posts by tags
- Order by summing multiple values
- How to extract specific post
- Woocommerce – Changing the order of the upsell products [closed]
- Changing sort order for presentation by Jetpack infinite scroll
- Include data from custom table in WP_Query
- wordpress ajax relationship query
- How to pass orderby params to $wpdb->prepare()?
- Debugging wp_query orderby for taxonomy
- Is it possible to query from external database? [duplicate]
- Include post content of linked posts in search
- Make a SQL query with wpdb in WordPress
- Getting additional columns from sql
- List of ways to access WordPress database?
- Getting rid of unwanted nonSQL syntax characters when debugging a query
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Query where ANDing slug values not working
- Slow Query On Search
- WP_Query: apply an SQL function to meta fileld value
- How to avoid filling up an array each time I run a WP_query?
- How to SQL query posts IDs by categories AND authors?
- Randomly select one of last 3 posts
- SQL query injection with fifu image
- Passing a SQL query to the WP Query
- WP_Query() not working as expected
- WP Query – grouping posts by same meta key, adding together values from another key
- Any way to use FETCH_KEY_PAIR with $wpdb?
- What is the equivalent WP_Query of a SQL Query?
- Translating WP query into to SQL query
- Filtering posts for unique titles, only the most recent
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- How to search CPTs in draft using get_page_by_title()
- Calculating efficiently on large amount of data generated by wp_query
- What argument does my function need to echo get_results() query results
- Include post_status check within $wpdb query
- Find by post_meta, then sort by post_meta, then sort by date (wp_posts)
- WP Query to order posts by multiple meta fields
- Custom WP_Query with SQL directives for getting posts by authors and terms
- How to return value from sql and display it
- orderby in WP_query doesn’t works
- WP_Query with several meta_query-statements and order by meta_value
- wpdb LIKE request shows all database data
- Convert a WP Query into a simpler SQL query to fetch only COUNT of posts
- Add custom argument to WP_Query and modify SQL where clause
- Group By query based on Custom Field
- How to make OR condition in WP_Query
- How to Access Global $multipage or Global $numpages outside the loop?
- Merging a complex query with post_rewind and splitting posts into two columns
- ‘posts_where’ filter not applying ‘WP_Query’ in `wp_ajax`
- Order taxonomy terms in alphabetical order
- is_search was called incorrectly
- How to do meta_query for attachments?
- Most commented last 24h, week, month, year and all time – posts_where
- WP_query sorting can’t sort danish letters (æ, ø, å)
- Dynamic User Id
- Issues with search after added meta_query
- Woocommerce: order posts by meta key
- Modify query posts
- How do I add an item to the WP admin menu?
- Multiple meta query from array
- Filter subpages in while loop from WP Query object
- show related articles in single.php template
- WP_Query to Retrieve Posts from WooCommerce Products that are Only in Catalog
- Search Filter With Custom Taxonomy and Custom Fields : How do I handle it via plugin?
- query_posts based on a meta_key
- Add category and user name to recently updated post list
- Main loop querying current template’s info only in custom category archive pages, not my posts