json - using jquery ui autocomplete in wordpress search form -
with using jquery ui autocomplete can suggest items when user fill textbox form remote source. in remote source have file this:
<?php sleep( 3 ); // no term passed - exit no response if (empty($_get['term'])) exit ; $q = strtolower($_get["term"]); // remove slashes if magically added if (get_magic_quotes_gpc()) $q = stripslashes($q); $items = array( "great bittern"=>"botaurus stellaris", "little grebe"=>"tachybaptus ruficollis", "black-necked grebe"=>"podiceps nigricollis", "heuglin's gull"=>"larus heuglini" ); $result = array(); foreach ($items $key=>$value) { if (strpos(strtolower($key), $q) !== false) { array_push($result, array("id"=>$value, "label"=>$key, "value" => strip_tags($key))); } if (count($result) > 11) break; } // json_encode available in php 5.2 , above, or can install pecl module in before versions echo json_encode($result); ?>
and it's o.k. , useful, want utilize in wordpress site since output of remote file json, want utilize wordpress plugin json api create json version of wordpress contents in remote source. utilize plugin can search in wordpress website , receive json results, example:
http://sushiant.com/?json=1&s=mysearchterm
but question how can utilize in remote source?
<?php if (empty($_get['term'])) exit ; $q = strtolower($_get["term"]); $s = file_get_contents("http://sushiant.com/?json=1&s=".$q); //some code here echo $s ?>
as mentioned here, wordpress json api returns many attributes each post listed in page. example, in mentioned case, have search results, homecoming attributes url, title, ... each post. after getting file content of results page in json (as have done), seems should decode php, select want via php , homecoming them through json_encode.
json wordpress wordpress-plugin jquery-ui-autocomplete
No comments:
Post a Comment