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've used a custom post type for one of my website. Custom post type contains scratch card data along with some custom fields.

I've developed an android application to manage those items from android device.

In the android app, I want to keep search feature which will help admin users to search card numbers to manage those.

I can use wordpress query to search by title.

$args = array("post_type" => "mytype", "name" => $title);
$query = get_posts( $args );

It can only provide result if I provide exact title. But I need to retrieve all items with similar title.

Any suggestion?

share|improve this question
Instead of using get_posts() you can use the default search query of WordPress which will provide you the results of the searched term. It will also provide all the matching results with all your search terms. – Rohit Pande Feb 11 '13 at 10:44
up vote 2 down vote accepted

You can use either search parameter of wp_query :

$args = array("post_type" => "mytype", "s" => $title);
$query = get_posts( $args );

Or you can get posts based on title throught wpdb class:

global $wpdb;
$posts = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_title LIKE '%s'"), '%'.$title.'%' );

Than you'll get post object in this form:

foreach ( $posts as $p ) 
    $post = get_post( $p );
    //run your output code here
share|improve this answer
Worked, thanks a lot man :) – Enthusiast Feb 11 '13 at 12:29

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.