0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Wordpress 開発のメモ

Last updated at Posted at 2020-02-04

SQL編

複数行

$rows = $wpdb->get_results($query, ARRAY_A); // ココに指定
foreach($rows as $row) {
   $id = $row['ID']; // 連想配列で返る
}

1つの値を返す

count(*) とか、特定の ID で絞った特定のフィールド値を取得するときとか、値が 1 つしか返ってこないときに使う。

$wpdb->get_var

1行返す

$select_result=$wpdb->get_row

$atai=$select_result->komoku 

ショートコードを使ってphpファイルを呼び出す方法

funciton.phpでの設定

function.php
//ショートコードを使ったphpファイルの呼び出し方法
function Include_my_php($params = array()) {
    extract(shortcode_atts(array(
        'file' => 'default'
    ), $params));
    ob_start();
    include(STYLESHEETPATH . "/$file.php");
    return ob_get_clean();
}
add_shortcode('myphp', 'Include_my_php');

投稿ページ・固定ページからショートコードで呼び出す

このケースではfunction.phpと同じ階層にmemeberslogin.phpファイルを作成してそれを呼び出している

hoge.html
[myphp file='memberslogin']

デバッグモード

wp-config.phpのdefine( 'WP_DEBUG', false );を変更する「false→true」

image.png

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?