Created
November 24, 2012 11:51
-
-
Save ShinichiNishikawa/4139337 to your computer and use it in GitHub Desktop.
カテゴリ/タクソノミをGETで受け取った時のバリデーション。Validate GET values against cattegories / taxonomies the site has.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/4139916
こっちのほうが100倍よい。