Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function array_push_associative(&$arr) {
- $args = func_get_args();
- foreach ($args as $arg) {
- if (is_array($arg)) {
- foreach ($arg as $key => $value) {
- $arr[$key] = $value;
- $ret++;
- }
- } else {
- $arr[$arg] = "";
- }
- }
- return $ret;
- }
- /**
- * Basic inhalt:
- * - Show Anime, published and ordered by title.
- *
- * @return array
- */
- function kn_anime_query_args($post_limit = 10, $post_per_page = NULL, $paged = NULL) {
- $args = array('post_type' => 'anime', 'post_status' => 'publish', 'orderby' => 'title', 'order' => 'ASC');
- if (!is_null($post_limit)) {
- $item1 = array('showposts' => $post_limit);
- array_push_associative($args, $item1);
- }
- if (!is_null($paged) && !is_null($post_per_page)) {
- $item1 = array('posts_per_page' => $post_per_page);
- $item2 = array('paged' => $paged);
- array_push_associative($args, $item1, $item2);
- }
- return $args;
- }
- function kn_anime_query_name($args = array(), $name = NULL){
- if (!is_null($name) && !isEmpty($name) && $name != '') {
- $item1 = array('post_title' => $name);
- array_push_associative($args, $item1);
- }
- }
- function kn_anime_query_add_season($args = array(), $season = NULL) {
- if (!is_null($season) && $season != 'ALL') {
- $item1 = array('Season' => $season);
- array_push_associative($args, $item1);
- }
- return $args;
- }
- function kn_anime_query_add_animetype($args = array(), $anime_type = NULL) {
- if (!is_null($anime_type) && $anime_type != 'ALL') {
- $item1 = array('a_types' => $anime_type);
- array_push_associative($args, $item1);
- }
- return $args;
- }
- function kn_anime_query_build_singlemeta($meta_name = '', $meta_item = '', $operator = 'LIKE'){
- $meta = array(
- 'key' => $meta_name,
- 'value' => $meta_item,
- 'compare' => $operator
- );
- return $meta;
- }
- function kn_anime_query_build_singletax($tax_name = '', $tax_items = array(), $operator = 'IN'){
- $tax = array(
- 'taxonomy' => $tax_name,
- 'field' => 'slug',
- 'terms' => $tax_items,
- // Operator to test. Possible values are 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
- // We choose 'IN' because we need to make sure the term is in the current array of posts
- // THIS A OR ^$anime_genre SEARCH!
- 'operator' => $operator
- );
- return $tax;
- }
- /**
- *
- * @param type $args
- * @param type $items
- * @param type $val => tax_query, meta_query
- * @param type $multi_relation
- * @return type
- */
- function kn_anime_query_add_multitval($args = array(), $items = array(), $val = 'tax_query', $multi_relation = 'AND') {
- if ($items == NULL || $args == NULL) {
- return $args;
- }
- $relation = array('relation' => $multi_relation);
- foreach ($items as $value) {
- array_push($relation, $value);
- }
- $item1 = array($val => $relation);
- array_push_associative($args, $item1);
- return $args;
- }
- function kn_anime_query_add_taxo($args = array(), $tax_name = NULL, $tax_items = NULL, $multi_relation = 'AND') {
- if ($tax_name == NULL || $tax_items == NULL) {
- return $args;
- }
- if (!is_array($tax_items)) {
- if (!is_null($tax_items) && $tax_items != 'ALL') {
- $item1 = array($tax_name => $tax_items);
- array_push_associative($args, $item1);
- }
- } else {
- $relation = array('relation' => $multi_relation);
- array_push($relation, array(
- 'taxonomy' => $tax_name,
- 'field' => 'slug',
- 'terms' => $tax_items,
- // Operator to test. Possible values are 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
- // We choose 'IN' because we need to make sure the term is in the current array of posts
- // THIS A OR ^$anime_genre SEARCH!
- 'operator' => 'IN'
- ));
- $item1 = array('tax_query' => $relation);
- array_push_associative($args, $item1);
- }
- return $args;
- }
- function kn_anime_query_add_genre($args = array(), $single_genre = true, $anime_genre = NULL, $multi_relation = 'AND') {
- if ($single_genre) {
- if (!is_null($anime_genre) && $anime_genre != 'ALL') {
- $item1 = array('Genre' => $anime_genre);
- array_push_associative($args, $item1);
- }
- } else {
- if (!is_array($anime_genre)) {
- $anime_genre = array($anime_genre);
- }
- $relation = array('relation' => $multi_relation);
- array_push($relation, array(
- 'taxonomy' => 'Genre',
- 'field' => 'slug',
- 'terms' => $anime_genre,
- // Operator to test. Possible values are 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
- // We choose 'IN' because we need to make sure the term is in the current array of posts
- // THIS A OR ^$anime_genre SEARCH!
- 'operator' => 'IN'
- ));
- $item1 = array('tax_query' => $relation);
- array_push_associative($args, $item1);
- }
- return $args;
- }
- // $relation = array('relation' => $multi_relation);
- //
- // foreach ($anime_genre as $key => $value) {
- // array_push($relation, array(
- // 'taxonomy' => 'Genre',
- // 'field' => 'slug',
- // 'terms' => $value,
- // // Operator to test. Possible values are 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
- // // We choose 'IN' because we need to make sure the term is in the current array of posts
- // 'operator' => 'IN',
- // ));
- // }
- // $item1 = array('tax_query' => $relation);
- // array_push_associative($args, $item1);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement