0

非WPテーブルからデータを取得するWordpressで自動提案検索を機能させようとしています。Allow PHP in Posts and Pages プラグインを使用しています。

私の検索ページは、ページで定義されているこのコードを実行します

[php]
$themeDir = get_bloginfo('template_url');

echo "<html>";
echo "<head>";
echo "<script type='text/javascript' src='jquery/js/jquery-1.4.2.min.js'></script>";
echo "<script type='text/javascript' src='jquery/js/jquery-ui-1.8.2.custom.min.js'></script>";
echo "<script type='text/javascript'> jQuery(document).ready(function(){
  $('#zipsearch').autocomplete({source:'http://127.0.0.1/wp/?page_id=230', minLength:2});
});

</script>";
echo "<link rel='stylesheet' href='jquery/css/smoothness/jquery-ui-1.8.2.custom.css' />";
echo "<style type='text/css'><!--

/* style the auto-complete response */
li.ui-menu-item { font-size:12px !important; }--></style>";
echo "</head>";

echo "<body>";

echo "<form onsubmit='return false;'>Enter a Zipcode:<input id='zipsearch' type='text' />";
echo "</form>";

echo "</body>";
echo "</html>";

[/php]

これから呼び出される結果ページ (page_id=230) は

[php]
//$term = mysql_real_escape_string($_REQUEST['term']);
$term = $_REQUEST['term'];
$sql = "select zip, city, state from zipcode where zip like '$term%' order by zip asc  limit 0,10";
$rs = mysql_query($sql);
$num = mysql_num_rows($rs);
$data = array();
if ($num > 0) {

  for ($i=0;$i<$num;$i++) {
    $zip = mysql_result($rs,$i,'zip');
    $city = mysql_result($rs,$i,'city');
    $state = mysql_result($rs,$i,'state');
    $data[] = array('label' => $zip .', '. $city.' '. $state,'value' => $zip);

  }
}

echo json_encode($data);
flush();
[/php]

この URL (/wp/?page_id=230&term=331) を入力すると、次の結果が得られるため、結果ページが機能しているようです。

[{"label":"33101, Miami FL","value":"33101"},{"label":"33102, Miami FL","value":"33102"},{"label":"33107, Miami FL","value":"33107"},{"label":"33109, Miami Beach FL","value":"33109"},{"label":"33110, Miami FL","value":"33110"},{"label":"33111, Miami FL","value":"33111"},{"label":"33112, Miami FL","value":"33112"},{"label":"33114, Miami FL","value":"33114"},{"label":"33116, Miami FL","value":"33116"},{"label":"33119, Miami Beach FL","value":"33119"}]

問題は、検索ウィンドウに結果が表示されないため、結果ページが jquery から適切に呼び出されているように見えないことです。要素を調べると、結果ページのマークアップが表示されます。

ここにスクリーンキャストがありますhttp://screencast.com/t/RH5NsErLf6BN何が起こるかを示しています。

私がはっきりしていることを願っています。そうでない場合は、どこで明確にできるか教えてください。

4

1 に答える 1

0

このページを見てください。メタデータを表示するための自動提案についてです

https://wordpress.stackexchange.com/questions/58592/auto-suggest-to-display-meta-data-but-not-to-include-it-upon-click

これはあなたを助けることができます!

于 2013-04-23T17:34:31.373 に答える