I’m an android developer. I made a php file on my host and I include wp-blog-header.php
. I used this file as a web service in the my application.
In the my app, there is a search part and I get term
as String and category
as id of user and send them to my php file .
now, I would like to search in post titles and return titles and ids of what user want.
function customSearch($term,$category){
.
. //To search by title and limit by category
.
}
I used prepare functions to get posts like below function, but I cannot find any function to search only in post titles.
function getLastItems()
{
$args = array(
'numberposts' => 5,
'offset' => 0,
'category' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'suppress_filters' => true );
$recent_posts = wp_get_recent_posts( $args, ARRAY_A );
$mjson = array();
foreach( $recent_posts as $recent ){
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($recent['ID']), array(400,300) );
$url_img = $thumb['0'];
$marr = array(
'id'=>$recent["ID"],
'title'=>$recent["post_title"],
'img'=>$url_img
);
array_push($mjson,$marr);
}
return $mjson ;
}//end get last items