plugins - Doubt using $wpbd->get_col for a single column

$table = $wpdb->prefix . 'posts';foreach ( $wpdb->get_col( "DESC " . $table, 0 ) as $column ){

$table = $wpdb->prefix . 'posts';
            foreach ( $wpdb->get_col( "DESC " . $table, 0 ) as $column ){//get all columns from wp_posts
                echo "<div><p>".
                $counter."- ".$column." => ".
                "<input class='input_triplify_posts' value='correspondence' id='correspondence".$counter."' mk='".$column."' />".
                "</p></div>";
                $counter++;
            }

Guys, with this code I can get all columns data from the table wp_posts in my database. I just want to get the data from a column named "guid" from the same table. What I have to modify in the code above? Thanks.

$table = $wpdb->prefix . 'posts';
            foreach ( $wpdb->get_col( "DESC " . $table, 0 ) as $column ){//get all columns from wp_posts
                echo "<div><p>".
                $counter."- ".$column." => ".
                "<input class='input_triplify_posts' value='correspondence' id='correspondence".$counter."' mk='".$column."' />".
                "</p></div>";
                $counter++;
            }

Guys, with this code I can get all columns data from the table wp_posts in my database. I just want to get the data from a column named "guid" from the same table. What I have to modify in the code above? Thanks.

Share Improve this question asked Jan 21, 2015 at 20:14 EduardoEduardo 211 silver badge3 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Try this. Hopefully I've interpreted your output correctly.

I'd recommend a good read of the $wpdb codex, particularly in relation to the get_col() method - http://codex.wordpress/Class_Reference/wpdb#SELECT_a_Column

global $wpdb;   // You won't need this unless this code is within a function

$query = $wpdb->prepare(
    'SELECT %1$s.guid FROM %1$s',
    $wpdb->posts
);
$results = $wpdb->get_col($query);
$counter = 1;   // Ignore this if you already set counter somewhere else, or change it as required

if(!empty($results)) : foreach($results as $result) :

        echo '<div><p>';

            printf(
                '%1$s- %2$s =>',
                $counter,
                $result
            );
            printf(
                '<input class="input_triplify_posts" value="correspondence" id="correspondence%1$s mk="%2$s" />',
                $counter,
                $result
            );

        echo '</p></div>';

        $counter++;

    endforeach;
endif;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742262780a4411220.html

相关推荐

  • plugins - Doubt using $wpbd-&gt;get_col for a single column

    $table = $wpdb->prefix . 'posts';foreach ( $wpdb->get_col( "DESC " . $table, 0 ) as $column ){

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信