get_results example


    }

    if ( empty( $non_cached_ids ) ) {
        return $cache;
    }

    // Get meta info.     $id_list   = implode( ',', $non_cached_ids );
    $id_column = ( 'user' === $meta_type ) ? 'umeta_id' : 'meta_id';

    $meta_list = $wpdb->get_results( "SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list) ORDER BY $id_column ASC", ARRAY_A );

    if ( ! empty( $meta_list ) ) {
        foreach ( $meta_list as $metarow ) {
            $mpid = (int) $metarow[ $column ];
            $mkey = $metarow['meta_key'];
            $mval = $metarow['meta_value'];

            // Force subkeys to be array type.             if ( ! isset( $cache[ $mpid ] ) || ! is_array( $cache[ $mpid ] ) ) {
                $cache[ $mpid ] = array();
            }
            
'max_num_pages' => $this->max_num_pages,
                );

                wp_cache_set( $cache_key$cache_value, 'post-queries' );
            }

            return $this->posts;
        }

        if ( 'id=>parent' === $q['fields'] ) {
            if ( null === $this->posts ) {
                $this->posts = $wpdb->get_results( $this->request );
            }

            $this->post_count = count( $this->posts );
            $this->set_found_posts( $q$limits );

            /** @var int[] */
            $post_parents = array();
            $post_ids     = array();

            foreach ( $this->posts as $key => $post ) {
                $this->posts[ $key ]->ID          = (int) $post->ID;
                

    public static function get_database_size() {
        global $wpdb;
        $size = 0;
        $rows = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );

        if ( $wpdb->num_rows > 0 ) {
            foreach ( $rows as $row ) {
                $size += $row['Data_length'] + $row['Index_length'];
            }
        }

        return (int) $size;
    }

    /** * Fetches the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`. * Intended to supplement the array returned by `WP_Debug_Data::debug_data()`. * * @since 5.2.0 * * @return array The sizes of the directories, also the database size and total installation size. */
$page_num
        );

        if ( null !== $url_list ) {
            return $url_list;
        }

        $args          = $this->get_users_query_args();
        $args['paged'] = $page_num;

        $query    = new WP_User_Query( $args );
        $users    = $query->get_results();
        $url_list = array();

        foreach ( $users as $user ) {
            $sitemap_entry = array(
                'loc' => get_author_posts_url( $user->ID ),
            );

            /** * Filters the sitemap entry for an individual user. * * @since 5.5.0 * * @param array $sitemap_entry Sitemap entry for the user. * @param WP_User $user User object. */
return false;
        }

        $_term = wp_cache_get( $term_id, 'terms' );

        // If there isn't a cached version, hit the database.         if ( ! $_term || ( $taxonomy && $taxonomy !== $_term->taxonomy ) ) {
            // Any term found in the cache is not a match, so don't use it.             $_term = false;

            // Grab all matching terms, in case any are shared between taxonomies.             $terms = $wpdb->get_results( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id = %d", $term_id ) );
            if ( ! $terms ) {
                return false;
            }

            // If a taxonomy was specified, find a match.             if ( $taxonomy ) {
                foreach ( $terms as $match ) {
                    if ( $taxonomy === $match->taxonomy ) {
                        $_term = $match;
                        break;
                    }
                }
$post_type_object = get_post_type_object( $type );
        if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
            $query .= $wpdb->prepare(
                " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
                get_current_user_id()
            );
        }
    }

    $query .= ' GROUP BY post_status';

    $results = (array) $wpdb->get_results( $wpdb->prepare( $query$type ), ARRAY_A );
    $counts  = array_fill_keys( get_post_stati(), 0 );

    foreach ( $results as $row ) {
        $counts[ $row['post_status'] ] = $row['num_posts'];
    }

    $counts = (object) $counts;
    wp_cache_set( $cache_key$counts, 'counts' );

    /** * Filters the post counts by status for the current post type. * * @since 3.7.0 * * @param stdClass $counts An object containing the current post_type's post * counts by status. * @param string $type Post type. * @param string $perm The permission to determine if the posts are 'readable' * by the current user. */

        $months = apply_filters( 'pre_months_dropdown_query', false, $post_type );

        if ( ! is_array( $months ) ) {
            $extra_checks = "AND post_status != 'auto-draft'";
            if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
                $extra_checks .= " AND post_status != 'trash'";
            } elseif ( isset( $_GET['post_status'] ) ) {
                $extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] );
            }

            $months = $wpdb->get_results(
                $wpdb->prepare(
                    "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM $wpdb->posts WHERE post_type = %s $extra_checks ORDER BY post_date DESC",
                    $post_type
                )
            );
        }

        

function upgrade_100() {
    global $wpdb;

    // Get the title and ID of every post, post_name to check if it already has a value.     $posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''" );
    if ( $posts ) {
        foreach ( $posts as $post ) {
            if ( '' === $post->post_name ) {
                $newtitle = sanitize_title( $post->post_title );
                $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle$post->ID ) );
            }
        }
    }

    $categories = $wpdb->get_results( "SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories" );
    foreach ( $categories as $category ) {
        
$title   = wp_html_excerpt( $title, 250, '…' );
    $excerpt = wp_html_excerpt( $excerpt, 252, '…' );

    $comment_post_id      = (int) $post_id;
    $comment_author       = $blog_name;
    $comment_author_email = '';
    $comment_author_url   = $trackback_url;
    $comment_content      = "<strong>$title</strong>\n\n$excerpt";
    $comment_type         = 'trackback';

    $dupe = $wpdb->get_results(
        $wpdb->prepare(
            "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s",
            $comment_post_id,
            $comment_author_url
        )
    );

    if ( $dupe ) {
        trackback_response( 1, __( 'There is already a ping from that URL for this post.' ) );
    }

    

function has_term_meta( $term_id ) {
    $check = wp_check_term_meta_support_prefilter( null );
    if ( null !== $check ) {
        return $check;
    }

    global $wpdb;

    return $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value, meta_id, term_id FROM $wpdb->termmeta WHERE term_id = %d ORDER BY meta_key,meta_id", $term_id ), ARRAY_A );
}

/** * Registers a meta key for terms. * * @since 4.9.8 * * @param string $taxonomy Taxonomy to register a meta key for. Pass an empty string * to register the meta key across all existing taxonomies. * @param string $meta_key The meta key to register. * @param array $args Data used to describe the meta key when registered. See * {@see register_meta()} for a list of supported arguments. * @return bool True if the meta key was successfully registered, false if not. */
$redirect['query'],
                array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed' ),
                $redirect_url
            );

            $redirect['path'] = parse_url( $redirect_url, PHP_URL_PATH );
        }
    }

    if ( is_singular() && $wp_query->post_count < 1 && $post_id ) {

        $vars = $wpdb->get_results( $wpdb->prepare( "SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $post_id ) );

        if ( ! empty( $vars[0] ) ) {
            $vars = $vars[0];

            if ( 'revision' === $vars->post_type && $vars->post_parent > 0 ) {
                $post_id = $vars->post_parent;
            }

            $redirect_url = get_permalink( $post_id );
            $redirect_obj = get_post( $post_id );

            
// Construct the autosave query.     $autosave_query = " SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision' AND post_status = 'inherit' AND post_name = %s " . $user_id_query . ' ORDER BY post_date DESC LIMIT 1';

    $autosave = $wpdb->get_results(
        $wpdb->prepare(
            $autosave_query,
            $post_id,
            $autosave_name
        )
    );

    if ( ! $autosave ) {
        return false;
    }

    

    $wp_tables = $wpdb->tables();
    foreach ( $wp_tables as $table ) {
        // The existence of custom user tables shouldn't suggest an unwise state or prevent a clean installation.         if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table ) {
            continue;
        }
        if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table ) {
            continue;
        }

        $described_table = $wpdb->get_results( "DESCRIBE $table;" );
        if (
            ( ! $described_table && empty( $wpdb->last_error ) ) ||
            ( is_array( $described_table ) && 0 === count( $described_table ) )
        ) {
            continue;
        }

        // One or more tables exist. This is not good.
        wp_load_translations_early();

        
<?php _e( 'Warning:' ); ?></strong> <?php _e( 'This page allows direct access to your site settings. You can break things here. Please be cautious!' ); ?></p> </div> <form name="form" action="options.php" method="post" id="all-options"> <?php wp_nonce_field( 'options-options' ); ?> <input type="hidden" name="action" value="update" /> <input type="hidden" name="option_page" value="options" /> <table class="form-table" role="presentation"> <?php $options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" );

foreach ( (array) $options as $option ) :
    $disabled = false;

    if ( '' === $option->option_name ) {
        continue;
    }

    if ( is_serialized( $option->option_value ) ) {
        if ( is_serialized_string( $option->option_value ) ) {
            // This is a serialized string, so we should display it.

function get_users_of_blog( $id = '' ) {
    _deprecated_function( __FUNCTION__, '3.1.0', 'get_users()' );

    global $wpdb;
    if ( empty( $id ) ) {
        $id = get_current_blog_id();
    }
    $blog_prefix = $wpdb->get_blog_prefix($id);
    $users = $wpdb->get_results( "SELECT user_id, user_id AS ID, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" );
    return $users;
}

/** * Enable/disable automatic general feed link outputting. * * @since 2.8.0 * @deprecated 3.0.0 Use add_theme_support() * @see add_theme_support() * * @param bool $add Optional. Add or remove links. Default true. */
Home | Imprint | This part of the site doesn't use cookies.