Currently this is working code that is queried as standalone search.php.
I have an issue that it searches beginning of title and not anywhere in title what I exactly need.
I have a feeling that I'm close to solution and I tried couple of things and it is probably something that I'm missing in post $args..
global $wp_query;
$type = 'qa';
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'showposts'=>100,
'orderby'=> 'menu_order',
'order' => 'DESC'
);
$my_query = null;
$my_query = new WP_Query($args);
$data = array();
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
$title = get_the_title();
$url = get_the_permalink();
$data[$title] = $url;
endwhile;
}
if(isset($_POST['latestQuery'])){
$latestQuery = $_POST['latestQuery'];
$latestQueryLength = strlen($latestQuery);
$result = array();
foreach($data as $name => $url){
if (substr(strtolower($name),0,$latestQueryLength) == strtolower($latestQuery)){
$result[$name] = $url;
}
}
echo json_encode($result);
}
This is already working in local environment.
JavaScript queries search.php file (above) where it gets json array returned based on query... for example "cla.."
{"Classic something":"http:\/\/www.something\/qa2","Classic something else":"http:\/\/www.something\/qa"}
So I have properly retuned two items that only have "Classic" mentioned in post title.
If I type "som" or "els" it doesn't return anything and it should match as well all "some" and "else" items.
I think it is not an issue with javascript code but with PHP code.
Thanks!