Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created October 6, 2010 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisasann/612770 to your computer and use it in GitHub Desktop.
Save hisasann/612770 to your computer and use it in GitHub Desktop.
<?php
/*
Template Name: Recent Entries
*/
?><?php
// クエリ文字列
$query = $_GET["re"];
// 検索件数
$allsearch =& new WP_Query("s=".$query."&showposts=-1");
// クエリ文字列から記事を検索
query_posts("s=".$query."&showposts=1&orderby=rand");
$title = null;
$permalink = null;
$count = null;
if (have_posts()) :
while (have_posts()) : the_post();
$convmap = array(0x0, 0x2FFFF, 0, 0xFFFF);
// 実体参照をデコード
$title = mb_decode_numericentity(get_the_title(), $convmap, 'UTF-8');
$permalink = get_permalink();
$count = $allsearch->post_count;
endwhile;
else :
$title = "検索結果がありませんでした。";
endif;
echo json_encode(array("title"=>$title, "permalink"=>$permalink, "count"=>$count));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment