public function value_for_set($value) { global $wf; if (WOOF::is_or_extends($value, "WOOF_Image")) { return $value->permalink(); } else if ($att = $wf->attachment($value)->exists()) { return $att->file->permalink(); } return $value; }
public function taxonomy($name = null) { if (is_null($name)) { return $this->the_taxonomy(); } if (WOOF::is_or_extends($name, "WOOF_Taxonomy")) { return $name; } $tax = get_taxonomy($name); if ($tax) { $tc = $this->get_taxonomy_class(); return new $tc($tax); } return new WOOF_Silent( sprintf( __( "Taxonomy %s does not exist", WOOF_DOMAIN ), $name ) ); }
public function is_collection($of = "") { if ($of) { $item = $this->first(); // note that an EMPTY collection will also be regarded as a collection of the given class // it's not correct to say it isn't, and this is likely to be the most elegant way to handle it. if ($item->exists()) { return WOOF::is_or_extends($item, $of); } } return TRUE; }
function in_a($terms, $taxonomy = NULL, $args = array(), $operator = "IN", $relation = "OR") { global $wf; if (!is_array($terms) && is_string($terms)) { $terms = explode(",", $terms); } $r = wp_parse_args( $args, array( 'posts_per_page' => -1 ) ); $r['post_type'] = $this->name; if (!isset($taxonomy)) { // if the taxonomy isn't set, $terms MUST be a single or collection of WOOF_Term objects for this to work if (WOOF::is_or_extends($terms, "WOOF_Term")) { $terms = $wf->collection( array($terms) ); } if (is_woof_collection($terms, "WOOF_Term") && count($terms)) { // now build a tax query $r['tax_query'] = array("relation" => $relation); $grouped = $terms->group_by("taxonomy_name"); foreach ($grouped as $taxonomy_name => $terms) { $r['tax_query'][] = array( 'taxonomy' => $taxonomy_name, 'terms' => $terms->extract("slug"), 'field' => 'slug', 'operator' => $operator ); } } else { return new WOOF_Silent(__("To perform a query without specifying a taxonomy, you must provide a single WOOF_Term or a collection of WOOF_Term objects", WOOF_DOMAIN)); } } else { $r['tax_query'] = array( array( 'taxonomy' => $taxonomy, 'terms' => $terms, 'field' => 'slug', 'operator' => $operator ) ); } return $wf->posts($r); }
function in_a($terms, $taxonomy = NULL, $args = array(), $operator = "IN", $relation = "OR") { global $wf; $posts = parent::in_a($terms, $taxonomy, $args, $operator, $relation); if ($wf->regard_field_terms()) { if (!is_array($terms) && is_string($terms)) { $terms = explode(",", $terms); } if (!isset($taxonomy)) { $term_objects = $terms; if (WOOF::is_or_extends($terms, "WOOF_Term")) { $terms = $wf->collection( array($terms) ); } } else { $term_objects = array(); foreach ($terms as $term) { $obj = $wf->term($term, $taxonomy); if (!is_woof_silent($obj)) { $term_objects[] = $obj; } } $term_objects = $wf->collection( $term_objects ); } if (is_woof_collection($term_objects, "WOOF_Term") && count($term_objects)) { $grouped = $term_objects->group_by( "taxonomy_name" ); $matching_posts = $wf->collection(); foreach ($grouped as $taxonomy_name => $terms) { $tax_posts = $wf->collection(); foreach ($terms as $term) { if ($operator == "IN") { $tax_posts->merge( $term->incoming( array("post_type" => $this->name ) ), false ); } else if ($operator == "AND") { $tax_posts = $tax_posts->intersect( $term->incoming( array("post_type" => $this->name ) ), "slug" ); } } if ($relation == "OR") { $matching_posts = $matching_posts->merge( $tax_posts, false ); } else { $matching_posts = $matching_posts->intersect( $tax_posts, "slug" ); } } $posts->merge( $matching_posts, false ); $posts->dedupe(); } } return $posts; }