/** * Add constraint to only contain the terms associated with the terms in the current list * * @param UTCW_QueryBuilder $builder * * @since 2.6 */ public function buildQuery(UTCW_QueryBuilder $builder) { $terms = $this->plugin->getCurrentQueryTerms(); $termIds = array_map(create_function('$term', 'return $term->term_id;'), $terms); $parameters = array(); foreach ($termIds as $termId) { $parameters[] = '%d'; $builder->addParameter($termId); } $builder->addStatement('AND term_id IN (' . join(',', $parameters) . ')'); }
/** * Add random sorting to query * * @param UTCW_QueryBuilder $builder * * @since 2.6 */ public function buildQuery(UTCW_QueryBuilder $builder) { $builder->addStatement('ORDER BY RAND()'); }
/** * Adds sorting by count to the query * * @param UTCW_QueryBuilder $builder * * @since 2.6 */ protected function buildQuery(UTCW_QueryBuilder $builder) { $builder->addStatement('ORDER BY count DESC'); }
/** * Returns the SQL query to be used when fetching terms * * @return string * @since 2.6 */ protected function getQuery() { $config = $this->plugin->get('dataConfig'); $db = $this->plugin->get('wpdb'); $builder = new UTCW_QueryBuilder($this->plugin); $builder->addAuthorConstraint($config->authors); $builder->addPostTypeConstraint($config->post_type); $builder->addPostStatusConstraint($this->plugin->isAuthenticatedUser(), $config->post_type); $builder->addDaysOldConstraint($config->days_old); $builder->addTaxonomyConstraint($config->taxonomy); $builder->addTagsListConstraint($config->tags_list_type, $config->tags_list, $config->taxonomy); $builder->addPostTermConstraint($config->post_term); $builder->addGrouping(); $builder->addMinimum($config->minimum); // Add statements from the strategy $this->buildQuery($builder); $builder->addMaxConstraint($config->max); $builder->addSort($config->order, $config->reverse, $config->case_sensitive); $query = $builder->getQuery(); $parameters = $builder->getParameters(); return $db->prepare($query, $parameters); }
/** * Add sorting by term_id (effectively by creation time) to query * * @param UTCW_QueryBuilder $builder * * @since 2.6 */ public function buildQuery(UTCW_QueryBuilder $builder) { $builder->addStatement('ORDER BY term_id DESC'); }