Skip to content

Instantly share code, notes, and snippets.

@ShinichiNishikawa
Created November 24, 2012 11:51
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 ShinichiNishikawa/4139337 to your computer and use it in GitHub Desktop.
Save ShinichiNishikawa/4139337 to your computer and use it in GitHub Desktop.
カテゴリ/タクソノミをGETで受け取った時のバリデーション。Validate GET values against cattegories / taxonomies the site has.
<?php
// example.com?what=abc&where=xyz
// category
$what = $_GET['what'];
$okCats = get_categories();
foreach ( $okCats as $oks ) {
$okCatsArr[] = $oks->name;
}
$ifWhat = in_array($what, $okCatsArr);
$what = $ifWhat ? $what: $ifWhat;
// taxonomy (district)
$where = $_GET['where'];
$okDistrict = get_terms( 'district' );
foreach ( $okDistrict as $oks ) {
$okDistrictArr[] = $oks->name;
}
$ifWhere = in_array($where, $okDistrictArr);
$where = $ifWhere ? $where: $ifWhere;
@ShinichiNishikawa
Copy link
Author

https://gist.github.com/4139916
こっちのほうが100倍よい。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment