LoginSignup
1
2

More than 5 years have passed since last update.

WordPress: DBから直接値を取得する方法(メモ)

Posted at
index.php
<?php
global $wpdb;
$args = array( 'posts_per_page' => -1, 'post_limits' => -1, 'post_type' => 'post' );
$wp_query = new WP_Query( $args );
?>

<?php if( $wp_query->have_posts()) : ?>
<? while($wp_query->have_posts()) : $wp_query -> the_post(); ?>

<?php
$str_result = "SELECT post_title FROM $wpdb->posts WHERE ID = ". $use_post->ID;
$var = $wpdb->get_var( $str_result );
$row = $wpdb->get_row( $str_result );
print_r( $var );
print_r( $row );
?>

<?php endwhile; ?>
<?php endif; ?>

グローバル変数(クラス?)の $wpdb を使うっぽい。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2