WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering if there was a way to make the search only look for the first letter in the posts title, basically let's say my search query is www.mysite.com/?s=q I'd like to get all posts that start with the letter "Q". Is this possible?

Thanks in advance.

share|improve this question
up vote 1 down vote accepted

I know it is too late but I hope it is going to help someone in the future You can add a filter to posts_where and add a regexp to limit it to the first letter. Wordpress documentation for posts_where

add_filter( 'posts_where' , 'posts_where' );

function posts_where( $where ) {

if( is_admin() ) {
    global $wpdb;

    if ( isset( $_GET['author_restrict_posts'] ) && !empty( $_GET['author_restrict_posts'] ) && intval( $_GET['author_restrict_posts'] ) != 0 ) {
        $author = intval( $_GET['author_restrict_posts'] );

        $where .= " AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id=$author )";
return $where;
share|improve this answer
Would you be able to clarify slightly? I'm not sure what is_admin is doing here (is this filtering only happening in the dashboard or when logged in as admin?) and I can't figure out where in the query you're specifying the 'first character' part of the search. – Gavin Jun 6 '12 at 3:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.