Advertisement
Guest User

build

a guest
May 14th, 2013
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. <?php
  2.  
  3. function array_push_associative(&$arr) {
  4. $args = func_get_args();
  5. foreach ($args as $arg) {
  6. if (is_array($arg)) {
  7. foreach ($arg as $key => $value) {
  8. $arr[$key] = $value;
  9. $ret++;
  10. }
  11. } else {
  12. $arr[$arg] = "";
  13. }
  14. }
  15. return $ret;
  16. }
  17.  
  18. /**
  19. * Basic inhalt:
  20. * - Show Anime, published and ordered by title.
  21. *
  22. * @return array
  23. */
  24. function kn_anime_query_args($post_limit = 10, $post_per_page = NULL, $paged = NULL) {
  25. $args = array('post_type' => 'anime', 'post_status' => 'publish', 'orderby' => 'title', 'order' => 'ASC');
  26.  
  27. if (!is_null($post_limit)) {
  28. $item1 = array('showposts' => $post_limit);
  29. array_push_associative($args, $item1);
  30. }
  31.  
  32. if (!is_null($paged) && !is_null($post_per_page)) {
  33. $item1 = array('posts_per_page' => $post_per_page);
  34. $item2 = array('paged' => $paged);
  35. array_push_associative($args, $item1, $item2);
  36. }
  37.  
  38. return $args;
  39. }
  40.  
  41. function kn_anime_query_name($args = array(), $name = NULL){
  42. if (!is_null($name) && !isEmpty($name) && $name != '') {
  43. $item1 = array('post_title' => $name);
  44. array_push_associative($args, $item1);
  45. }
  46. }
  47.  
  48. function kn_anime_query_add_season($args = array(), $season = NULL) {
  49. if (!is_null($season) && $season != 'ALL') {
  50. $item1 = array('Season' => $season);
  51. array_push_associative($args, $item1);
  52. }
  53. return $args;
  54. }
  55.  
  56. function kn_anime_query_add_animetype($args = array(), $anime_type = NULL) {
  57. if (!is_null($anime_type) && $anime_type != 'ALL') {
  58. $item1 = array('a_types' => $anime_type);
  59. array_push_associative($args, $item1);
  60. }
  61. return $args;
  62. }
  63.  
  64. function kn_anime_query_build_singlemeta($meta_name = '', $meta_item = '', $operator = 'LIKE'){
  65. $meta = array(
  66. 'key' => $meta_name,
  67. 'value' => $meta_item,
  68. 'compare' => $operator
  69. );
  70.  
  71. return $meta;
  72. }
  73.  
  74. function kn_anime_query_build_singletax($tax_name = '', $tax_items = array(), $operator = 'IN'){
  75. $tax = array(
  76. 'taxonomy' => $tax_name,
  77. 'field' => 'slug',
  78. 'terms' => $tax_items,
  79. // Operator to test. Possible values are 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
  80. // We choose 'IN' because we need to make sure the term is in the current array of posts
  81. // THIS A OR ^$anime_genre SEARCH!
  82. 'operator' => $operator
  83. );
  84.  
  85. return $tax;
  86. }
  87. /**
  88. *
  89. * @param type $args
  90. * @param type $items
  91. * @param type $val => tax_query, meta_query
  92. * @param type $multi_relation
  93. * @return type
  94. */
  95. function kn_anime_query_add_multitval($args = array(), $items = array(), $val = 'tax_query', $multi_relation = 'AND') {
  96.  
  97. if ($items == NULL || $args == NULL) {
  98. return $args;
  99. }
  100.  
  101. $relation = array('relation' => $multi_relation);
  102.  
  103. foreach ($items as $value) {
  104. array_push($relation, $value);
  105. }
  106.  
  107. $item1 = array($val => $relation);
  108. array_push_associative($args, $item1);
  109.  
  110. return $args;
  111. }
  112.  
  113. function kn_anime_query_add_taxo($args = array(), $tax_name = NULL, $tax_items = NULL, $multi_relation = 'AND') {
  114.  
  115. if ($tax_name == NULL || $tax_items == NULL) {
  116. return $args;
  117. }
  118.  
  119. if (!is_array($tax_items)) {
  120. if (!is_null($tax_items) && $tax_items != 'ALL') {
  121. $item1 = array($tax_name => $tax_items);
  122. array_push_associative($args, $item1);
  123. }
  124. } else {
  125. $relation = array('relation' => $multi_relation);
  126. array_push($relation, array(
  127. 'taxonomy' => $tax_name,
  128. 'field' => 'slug',
  129. 'terms' => $tax_items,
  130. // Operator to test. Possible values are 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
  131. // We choose 'IN' because we need to make sure the term is in the current array of posts
  132. // THIS A OR ^$anime_genre SEARCH!
  133. 'operator' => 'IN'
  134. ));
  135.  
  136. $item1 = array('tax_query' => $relation);
  137. array_push_associative($args, $item1);
  138. }
  139. return $args;
  140. }
  141.  
  142. function kn_anime_query_add_genre($args = array(), $single_genre = true, $anime_genre = NULL, $multi_relation = 'AND') {
  143.  
  144. if ($single_genre) {
  145. if (!is_null($anime_genre) && $anime_genre != 'ALL') {
  146. $item1 = array('Genre' => $anime_genre);
  147. array_push_associative($args, $item1);
  148. }
  149. } else {
  150. if (!is_array($anime_genre)) {
  151. $anime_genre = array($anime_genre);
  152. }
  153. $relation = array('relation' => $multi_relation);
  154.  
  155. array_push($relation, array(
  156. 'taxonomy' => 'Genre',
  157. 'field' => 'slug',
  158. 'terms' => $anime_genre,
  159. // Operator to test. Possible values are 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
  160. // We choose 'IN' because we need to make sure the term is in the current array of posts
  161. // THIS A OR ^$anime_genre SEARCH!
  162. 'operator' => 'IN'
  163. ));
  164.  
  165. $item1 = array('tax_query' => $relation);
  166. array_push_associative($args, $item1);
  167. }
  168. return $args;
  169. }
  170.  
  171. // $relation = array('relation' => $multi_relation);
  172. //
  173. // foreach ($anime_genre as $key => $value) {
  174. // array_push($relation, array(
  175. // 'taxonomy' => 'Genre',
  176. // 'field' => 'slug',
  177. // 'terms' => $value,
  178. // // Operator to test. Possible values are 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
  179. // // We choose 'IN' because we need to make sure the term is in the current array of posts
  180. // 'operator' => 'IN',
  181. // ));
  182. // }
  183. // $item1 = array('tax_query' => $relation);
  184. // array_push_associative($args, $item1);
  185. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement