get_col example

if ( $args['start_date'] ) {
            $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", gmdate( 'Y-m-d', strtotime( $args['start_date'] ) ) );
        }

        if ( $args['end_date'] ) {
            $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", gmdate( 'Y-m-d', strtotime( '+1 month', strtotime( $args['end_date'] ) ) ) );
        }
    }

    // Grab a snapshot of post IDs, just in case it changes during the export.     $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where);

    /* * Get the requested terms ready, empty unless posts filtered by category * or all content. */
    $cats  = array();
    $tags  = array();
    $terms = array();
    if ( isset( $term ) && $term ) {
        $cat  = get_term( $term['term_id'], 'category' );
        $cats = array( $cat->term_id => $cat );
        
$user->remove_all_caps();

    $blogs = get_blogs_of_user( $user_id );
    if ( count( $blogs ) === 0 ) {
        update_user_meta( $user_id, 'primary_blog', '' );
        update_user_meta( $user_id, 'source_domain', '' );
    }

    if ( $reassign ) {
        $reassign = (int) $reassign;
        $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $user_id ) );
        $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $user_id ) );

        if ( ! empty( $post_ids ) ) {
            $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign$user_id ) );
            array_walk( $post_ids, 'clean_post_cache' );
        }

        if ( ! empty( $link_ids ) ) {
            $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign$user_id ) );
            array_walk( $link_ids, 'clean_bookmark_cache' );
        }
    }
// Set autoload to no for these options.     $fat_options = array(
        'moderation_keys',
        'recently_edited',
        'disallowed_keys',
        'uninstall_plugins',
        'auto_plugin_theme_update_emails',
    );

    $keys             = "'" . implode( "', '", array_keys( $options ) ) . "'";
    $existing_options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name in ( $keys )" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
    $insert = '';

    foreach ( $options as $option => $value ) {
        if ( in_array( $option$existing_options, true ) ) {
            continue;
        }

        if ( in_array( $option$fat_options, true ) ) {
            $autoload = 'no';
        } else {
            
{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']} ";

        if ( $this->query_vars['count'] ) {
            return (int) $wpdb->get_var( $this->request );
        } else {
            $comment_ids = $wpdb->get_col( $this->request );
            return array_map( 'intval', $comment_ids );
        }
    }

    /** * Populates found_comments and max_num_pages properties for the current * query if the limit clause was used. * * @since 4.6.0 * * @global wpdb $wpdb WordPress database abstraction object. */
if ( $doaction ) {
    check_admin_referer( 'bulk-comments' );

    if ( 'delete_all' === $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) {
        /** * @global wpdb $wpdb WordPress database abstraction object. */
        global $wpdb;

        $comment_status = wp_unslash( $_REQUEST['comment_status'] );
        $delete_time    = wp_unslash( $_REQUEST['pagegen_timestamp'] );
        $comment_ids    = $wpdb->get_col(
            $wpdb->prepare(
                "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s AND %s > comment_date_gmt",
                $comment_status,
                $delete_time
            )
        );
        $doaction       = 'delete';
    } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
        $comment_ids = $_REQUEST['delete_comments'];
        $doaction    = $_REQUEST['action'];
    }
        } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s )
            || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s )
            || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s )
            || preg_match( '/^[0-9]{1,3}\.$/', $s )
        ) {
            // IPv4 address.             $sql = $wpdb->prepare(
                "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s",
                $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' )
            );

            $reg_blog_ids = $wpdb->get_col( $sql );

            if ( $reg_blog_ids ) {
                $args['site__in'] = $reg_blog_ids;
            }
        } elseif ( is_numeric( $s ) && empty( $wild ) ) {
            $args['ID'] = $s;
        } else {
            $args['search'] = $s;

            if ( ! is_subdomain_install() ) {
                $args['search_columns'] = array( 'path' );
            }
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options' );

    // Update comments table to use comment_type.     $wpdb->query( "UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'" );
    $wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" );

    // Some versions have multiple duplicate option_name rows with the same values.     $options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" );
    foreach ( $options as $option ) {
        if ( 1 != $option->dupes ) { // Could this be done in the query?             $limit    = $option->dupes - 1;
            $dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) );
            if ( $dupe_ids ) {
                $dupe_ids = implode( ',', $dupe_ids );
                $wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" );
            }
        }
    }

    make_site_theme();
}

/** * Execute changes made in WordPress 2.0. * * @ignore * @since 2.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * @global int $wp_current_db_version The old (current) database version. */
$delete_limit = apply_filters( 'akismet_delete_comment_limit', defined( 'AKISMET_DELETE_LIMIT' ) ? AKISMET_DELETE_LIMIT : 10000 );
        $delete_limit = max( 1, intval( $delete_limit ) );

        /** * Determines how many days a comment will be left in the Spam queue before being deleted. * * @param int The default number of days. */
        $delete_interval = apply_filters( 'akismet_delete_comment_interval', 15 );
        $delete_interval = max( 1, intval( $delete_interval ) );

        while ( $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_id FROM {$wpdb->comments} WHERE DATE_SUB(NOW(), INTERVAL %d DAY) > comment_date_gmt AND comment_approved = 'spam' LIMIT %d", $delete_interval$delete_limit ) ) ) {
            if ( empty( $comment_ids ) )
                return;

            $wpdb->queries = array();

            $comments = array();

            foreach ( $comment_ids as $comment_id ) {
                $comments[ $comment_id ] = get_comment( $comment_id );

                do_action( 'delete_comment', $comment_id$comments[ $comment_id ] );
                

    do_action( 'delete_comment', $comment->comment_ID, $comment );

    // Move children up a level.     $children = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID ) );
    if ( ! empty( $children ) ) {
        $wpdb->update( $wpdb->comments, array( 'comment_parent' => $comment->comment_parent ), array( 'comment_parent' => $comment->comment_ID ) );
        clean_comment_cache( $children );
    }

    // Delete metadata.     $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment->comment_ID ) );
    foreach ( $meta_ids as $mid ) {
        delete_metadata_by_mid( 'comment', $mid );
    }

    
if ( null === $keys ) {
        /** * Filters the number of custom fields to retrieve for the drop-down * in the Custom Fields meta box. * * @since 2.1.0 * * @param int $limit Number of custom fields to retrieve. Default 30. */
        $limit = apply_filters( 'postmeta_form_limit', 30 );

        $keys = $wpdb->get_col(
            $wpdb->prepare(
                "SELECT DISTINCT meta_key FROM $wpdb->postmeta WHERE meta_key NOT BETWEEN '_' AND '_z' HAVING meta_key NOT LIKE %s ORDER BY meta_key LIMIT %d",
                $wpdb->esc_like( '_' ) . '%',
                $limit
            )
        );
    }

    do_action( 'wpmu_delete_user', $id$user );

    $blogs = get_blogs_of_user( $id );

    if ( ! empty( $blogs ) ) {
        foreach ( $blogs as $blog ) {
            switch_to_blog( $blog->userblog_id );
            remove_user_from_blog( $id$blog->userblog_id );

            $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
            foreach ( (array) $post_ids as $post_id ) {
                wp_delete_post( $post_id );
            }

            // Clean links.             $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );

            if ( $link_ids ) {
                foreach ( $link_ids as $link_id ) {
                    wp_delete_link( $link_id );
                }
            }
$pagenum       = $wp_list_table->get_pagenum();

// Handle bulk actions. $doaction = $wp_list_table->current_action();

if ( $doaction ) {
    check_admin_referer( 'bulk-media' );

    $post_ids = array();

    if ( 'delete_all' === $doaction ) {
        $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
        $doaction = 'delete';
    } elseif ( isset( $_REQUEST['media'] ) ) {
        $post_ids = $_REQUEST['media'];
    } elseif ( isset( $_REQUEST['ids'] ) ) {
        $post_ids = explode( ',', $_REQUEST['ids'] );
    }
    $post_ids = array_map( 'intval', (array) $post_ids );

    $location = 'upload.php';
    $referer  = wp_get_referer();
    if ( $referer ) {
        
$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
            $climits  = ( ! empty( $climits ) ) ? $climits : '';

            $comments_request = "SELECT $distinct {$wpdb->comments}.comment_ID FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";

            $key          = md5( $comments_request );
            $last_changed = wp_cache_get_last_changed( 'comment' ) . ':' . wp_cache_get_last_changed( 'posts' );

            $cache_key   = "comment_feed:$key:$last_changed";
            $comment_ids = wp_cache_get( $cache_key, 'comment-queries' );
            if ( false === $comment_ids ) {
                $comment_ids = $wpdb->get_col( $comments_request );
                wp_cache_add( $cache_key$comment_ids, 'comment-queries' );
            }
            _prime_comment_caches( $comment_ids );

            // Convert to WP_Comment.             /** @var WP_Comment[] */
            $this->comments      = array_map( 'get_comment', $comment_ids );
            $this->comment_count = count( $this->comments );

            $post_ids = array();

            
{$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']} ";

        if ( $this->query_vars['count'] ) {
            return (int) $wpdb->get_var( $this->request );
        }

        $network_ids = $wpdb->get_col( $this->request );

        return array_map( 'intval', $network_ids );
    }

    /** * Populates found_networks and max_num_pages properties for the current query * if the limit clause was used. * * @since 4.6.0 * * @global wpdb $wpdb WordPress database abstraction object. */

    function maybe_create_table( $table_name$create_ddl ) {
        global $wpdb;

        foreach ( $wpdb->get_col( 'SHOW TABLES', 0 ) as $table ) {
            if ( $table === $table_name ) {
                return true;
            }
        }

        // Didn't find it, so try to create it.         // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- No applicable variables for this query.         $wpdb->query( $create_ddl );

        // We cannot directly tell whether this succeeded!         foreach ( $wpdb->get_col( 'SHOW TABLES', 0 ) as $table ) {
            
Home | Imprint | This part of the site doesn't use cookies.