本文整理汇总了PHP中wpdb::get_col方法的典型用法代码示例。如果您正苦于以下问题:PHP wpdb::get_col方法的具体用法?PHP wpdb::get_col怎么用?PHP wpdb::get_col使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wpdb
的用法示例。
在下文中一共展示了wpdb::get_col方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete_terms
/**
* Deletes all plugin terms.
*
* @return void
*/
private function delete_terms()
{
$query = "\nSELECT term_id\nFROM {$this->wpdb->term_taxonomy}\nWHERE taxonomy = %s\nLIMIT 500";
$query = $this->wpdb->prepare($query, $this->taxonomy);
while ($term_ids = $this->wpdb->get_col($query)) {
foreach ($term_ids as $term_id) {
wp_delete_term($term_id, $this->taxonomy);
}
}
}
示例2: get_related_sites
/**
* Fetch related sites.
*
* @param int $site_id
* @return array
*/
public function get_related_sites($site_id = 0)
{
$site_id = $this->empty_site_id_fallback($site_id);
if (isset($this->related_sites[$site_id])) {
return $this->related_sites[$site_id];
}
$sql = $this->get_related_sites_sql($site_id);
$this->related_sites[$site_id] = $this->wpdb->get_col($sql);
return $this->related_sites[$site_id];
}
示例3: uninstall
/**
* Uninstalls all plugin data.
*
* @return void
*/
public function uninstall()
{
if (is_multisite()) {
foreach ($this->wpdb->get_col("SELECT blog_id FROM {$this->wpdb->blogs}") as $blog_id) {
switch_to_blog($blog_id);
$this->delete_options();
restore_current_blog();
}
} else {
$this->delete_options();
}
}
示例4: reassign_terms
/**
* Performs an SQL query assigning all terms to their correct language equivalent if it exists.
* This should only be run after the previous functionality in here has finished.
* Afterwards the term counts are recalculated globally, since term assignments bypassing the WordPress Core,
* will not trigger any sort of update on those.
*/
private function reassign_terms()
{
$update_query = $this->wpdb->prepare("UPDATE {$this->wpdb->term_relationships} AS o,\n\t\t\t\t\t{$this->wpdb->prefix}icl_translations AS ic,\n\t\t\t\t\t{$this->wpdb->prefix}icl_translations AS iw,\n\t\t\t\t\t{$this->wpdb->prefix}icl_translations AS ip,\n\t\t\t\t\t{$this->wpdb->posts} AS p\n\t\t\t\t\t\tSET o.term_taxonomy_id = ic.element_id\n\t\t\t\t\t\tWHERE ic.trid = iw.trid\n\t\t\t\t\t\t\tAND ic.element_type = iw.element_type\n\t\t\t\t\t\t\tAND iw.element_id = o.term_taxonomy_id\n\t\t\t\t\t\t\tAND ic.language_code = ip.language_code\n\t\t\t\t\t\t\tAND ip.element_type = CONCAT('post_', p.post_type)\n\t\t\t\t\t\t\tAND ip.element_id = p.ID\n\t\t\t\t\t\t\tAND o.object_id = p.ID\n\t\t\t\t\t\t\tAND o.term_taxonomy_id != ic.element_id\n\t\t\t\t\t\t\tAND iw.element_type = %s", 'tax_' . $this->taxonomy);
$rows_affected = $this->wpdb->query($update_query);
if ($rows_affected) {
$term_ids = $this->wpdb->get_col($this->wpdb->prepare("SELECT term_taxonomy_id FROM {$this->wpdb->term_taxonomy} WHERE taxonomy = %s", $this->taxonomy));
// Do not run the count update on taxonomies that are not actually registered as proper taxonomy objects, e.g. WooCommerce Product Attributes.
$taxonomy_object = $this->sitepress->get_wp_api()->get_taxonomy($this->taxonomy);
if ($taxonomy_object && isset($taxonomy_object->object_type)) {
$this->sitepress->get_wp_api()->wp_update_term_count($term_ids, $this->taxonomy);
}
}
}
示例5: delete_items_for_deleted_site
/**
* Deletes all remote MultilingualPress nav menu items linking to the (to-be-deleted) site with the given ID.
*
* @param int $deleted_site_id The ID of the to-be-deleted site.
*
* @return void
*/
public function delete_items_for_deleted_site($deleted_site_id)
{
$query = "\nSELECT blog_id\nFROM {$this->wpdb->blogs}\nWHERE blog_id != %d";
$query = $this->wpdb->prepare($query, $deleted_site_id);
foreach ($this->wpdb->get_col($query) as $site_id) {
switch_to_blog($site_id);
$query = "\nSELECT p.ID\nFROM {$this->wpdb->posts} p\nINNER JOIN {$this->wpdb->postmeta} pm\nON p.ID = pm.post_id\nWHERE pm.meta_key = %s\n\tAND pm.meta_value = %s";
$query = $this->wpdb->prepare($query, $this->meta_key, $deleted_site_id);
foreach ($this->wpdb->get_col($query) as $post_id) {
wp_delete_post($post_id, true);
}
restore_current_blog();
}
}
示例6: get_tables
/**
* Returns an array of tables in the database.
*
* if multisite && mainsite: all tables of the site
* if multisite && subsite: all tables of current blog
* if single site : all tabkes of the site
*
* @access public
* @return array
*/
public function get_tables()
{
if (function_exists('is_multisite') && is_multisite()) {
if (is_main_site()) {
$tables = $this->wpdb->get_col("SHOW TABLES LIKE'" . $this->wpdb->base_prefix . "%'");
} else {
$blog_id = get_current_blog_id();
$tables = $this->wpdb->get_col("SHOW TABLES LIKE '" . $this->wpdb->base_prefix . absint($blog_id) . "\\_%'");
}
} else {
$tables = $this->wpdb->get_col("SHOW TABLES LIKE'" . $this->wpdb->base_prefix . "%'");
}
return $tables;
}
示例7: uninstall
/**
* Uninstalls all plugin data.
*
* @return void
*/
public function uninstall()
{
$option_name = $this->option->get_name();
if (is_multisite()) {
foreach ($this->wpdb->get_col("SELECT blog_id FROM {$this->wpdb->blogs}") as $blog_id) {
switch_to_blog($blog_id);
delete_option($this->version_option_name);
delete_option($option_name);
}
restore_current_blog();
} else {
delete_option($this->version_option_name);
delete_option($option_name);
}
}
示例8: query
/**
* Execute the query, with the current variables.
*
* @since 3.1.0
*/
public function query()
{
$qv =& $this->query_vars;
$this->request = "SELECT {$this->query_fields} {$this->query_from} {$this->query_where} {$this->query_orderby} {$this->query_limit}";
if (is_array($qv['fields']) || 'all' == $qv['fields']) {
$this->results = $this->db->get_results($this->request);
} else {
$this->results = $this->db->get_col($this->request);
}
/**
* Filters SELECT FOUND_ROWS() query for the current WP_User_Query instance.
*
* @since 3.2.0
*
* @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query.
*/
if (isset($qv['count_total']) && $qv['count_total']) {
$this->total_users = $this->db->get_var(apply_filters('found_users_query', 'SELECT FOUND_ROWS()'));
}
if (!$this->results) {
return;
}
if ('all_with_meta' == $qv['fields']) {
cache_users($this->results);
$r = array();
foreach ($this->results as $userid) {
$r[$userid] = new WP_User($userid, '', $qv['blog_id']);
}
$this->results = $r;
} elseif ('all' == $qv['fields']) {
foreach ($this->results as $key => $user) {
$this->results[$key] = new WP_User($user, '', $qv['blog_id']);
}
}
}
示例9: get_related_sites
/**
* Fetch related sites.
*
* @param int $site_id
* @param bool $public TRUE if you want just public sites.
* @return array
*/
public function get_related_sites($site_id = 0, $public = TRUE)
{
$site_id = $this->empty_site_id_fallback($site_id);
$key = "{$site_id}-" . (int) $public;
if (isset($this->related_sites[$key])) {
return $this->related_sites[$key];
}
// There are no public sites. No need to run a query in this case.
if ($public && array() === $this->public_site_ids) {
$this->related_sites[$key] = array();
return array();
}
$sql = $this->get_related_sites_sql($site_id, $public);
$this->related_sites[$key] = $this->wpdb->get_col($sql);
return $this->related_sites[$key];
}
示例10: on_sub
public function on_sub($sub_id)
{
if ($this->ID == 0) {
return false;
}
$result = $this->_wpdb->get_col(sprintf('SELECT rel_id FROM %s WHERE user_id = %d AND sub_id = %d', MEMBERSHIP_TABLE_RELATIONS, $this->ID, $sub_id));
return apply_filters('membership_on_sub', !empty($result), $sub_id, $this->ID);
}
示例11: getIdsForRestriction
/**
* Returns all ids from DB suitable for given restriction.
* E.g. all comment_id values where comment_post_id = 1
* @param string $entityName
* @param array $where
* @return array
*/
private function getIdsForRestriction($entityName, $where)
{
$idColumnName = $this->dbSchemaInfo->getEntityInfo($entityName)->idColumnName;
$table = $this->dbSchemaInfo->getPrefixedTableName($entityName);
$sql = "SELECT {$idColumnName} FROM {$table} WHERE ";
$sql .= join(" AND ", array_map(function ($column) {
return "`{$column}` = %s";
}, array_keys($where)));
$ids = $this->database->get_col($this->database->prepare($sql, $where));
return $ids;
}
示例12: isset
function global_site_search_output($content)
{
global $wp_query;
if (!isset($wp_query->query_vars['namespace']) || $wp_query->query_vars['namespace'] != 'gss' || $wp_query->query_vars['type'] != 'search') {
return $content;
}
// We are on a search results page
$global_site_search_per_page = get_site_option('global_site_search_per_page', '10');
$global_site_search_post_type = get_site_option('global_site_search_post_type', 'post');
//=====================================//
//
$phrase = isset($wp_query->query_vars['search']) ? urldecode($wp_query->query_vars['search']) : '';
if (empty($phrase) && isset($_REQUEST['phrase'])) {
$phrase = trim($_REQUEST['phrase']);
}
if (empty($phrase)) {
ob_start();
global_site_search_form();
$content .= ob_get_clean();
return $content;
}
$theauthor = get_user_by('login', $phrase);
if (is_object($theauthor)) {
$author_id = $theauthor->ID;
}
$parameters = array();
if (isset($author_id) && is_numeric($author_id) && $author_id != 0) {
$parameters['author'] = $author_id;
} else {
$parameters['s'] = $phrase;
}
$parameters['post_type'] = $global_site_search_post_type != 'all' ? $global_site_search_post_type : $this->db->get_col("SELECT post_type FROM {$this->db->base_prefix}network_posts GROUP BY post_type");
// Add in the start and end numbers
$parameters['posts_per_page'] = absint($global_site_search_per_page);
// Set the page number
if (!isset($wp_query->query_vars['paged']) || $wp_query->query_vars['paged'] <= 1) {
$parameters['paged'] = 1;
$start = 0;
} else {
$parameters['paged'] = absint($wp_query->query_vars['paged']);
$start = $global_site_search_per_page * ($wp_query->query_vars['paged'] - 1);
}
//=====================================//
ob_start();
$network_query_posts = network_query_posts($parameters);
include global_site_search_locate_template('global-site-search.php');
$content .= ob_get_clean();
return $content;
}
示例13: wpdb
function get_tables_saved($con_type, $username, $password, $database, $host)
{
global $wpdb;
if ($con_type == 'local') {
$query = "SHOW TABLES";
$tables = $wpdb->get_col($query);
} else {
if ($con_type == 'remote') {
$wpdb_temp = new wpdb($username, $password, $database, $host);
$query = "SHOW TABLES";
$tables = $wpdb_temp->get_col($query);
}
}
//$wpdb= new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
return $tables;
}
示例14: array
/**
* Return a record as an array based on a given SQL select statement keys and params list.
*
* Executes wpdb get_row using the specified SQL statement.
* If more than one row is returned by the query, only the specified row is returned by the function, but all rows are cached for later use.
* Returns NULL if no result is found
*
* @link https://codex.wordpress.org/Class_Reference/wpdb WordPress WPDB Class
*
* @param string[] $commandList
* @param mixed[] $params
* @param int $offset
* @param mixed $type the type of object/array/etc. to return see wpdb get_row.
* @param string $mode = get_row or get_col to fetch a single row or multiple rows of a single column
* @return mixed the database array_a or object.
*/
function get_Record($commandList, $params = array(), $offset = 0, $type = ARRAY_A, $mode = 'get_row')
{
$this->is_Extended();
$query = $this->get_SQL($commandList);
// No placeholders, just call direct with no prepare
//
if (strpos($query, '%') !== false) {
$query = $this->db->prepare($query, $params);
}
// get_row (default) or get_col based on the mode
if ($mode === 'get_col') {
$results = $this->db->get_col($query, $offset);
} else {
$results = $this->db->get_row($query, $type, $offset);
}
return $results;
}
示例15: strpos
function allowed_redirect_hosts($allowed_hosts)
{
if (!empty($_REQUEST['redirect_to'])) {
$redirect_url = parse_url($_REQUEST['redirect_to']);
if (isset($redirect_url['host'])) {
$network_home_url = parse_url(network_home_url());
if ($redirect_url['host'] != $network_home_url['host']) {
$pos = strpos($redirect_url['host'], '.');
if ($pos !== false && substr($redirect_url['host'], $pos + 1) === $network_home_url['host']) {
$allowed_hosts[] = $redirect_url['host'];
}
$bid = $this->db->get_var("SELECT blog_id FROM {$this->dmtable} WHERE domain = '{$redirect_url['host']}' ORDER BY id LIMIT 1");
if ($bid) {
$allowed_hosts[] = $redirect_url['host'];
}
}
}
} else {
$domains = (array) $this->db->get_col(sprintf("SELECT domain FROM %s WHERE blog_id = %d ORDER BY id ASC", DOMAINMAP_TABLE_MAP, $this->db->blogid));
$original = $this->db->get_var("SELECT domain FROM {$this->db->blogs} WHERE blog_id = " . intval($this->db->blogid));
$allowed_hosts = array_unique(array_merge($allowed_hosts, $domains, array($original)));
}
return $allowed_hosts;
}