« ワードプレスのキャッシュ | メイン | ワードプレス 有効・無効・アンインスコ時の処理をつける »
2020年09月28日
ワードプレスで外部からデータ取得
file_get_contentsでもいいんだが、なんかお作法あるようなので、正しいかわからないけどメモ
$result = wp_remote_get($url, $options);
https://wpdocs.osdn.jp/関数リファレンス/wp_remote_get
GETメソッドを使用してHTTPリクエストからの生の応答を取得します。
結果は、HTTPヘッダとコンテンツが含まれています。
※失敗時はWP_Errorが帰ってくる
HTTP POSTメソッドを使うには wp_remote_post() / enを参照ください。
デフォルトのパラメーター
$args = array(
'timeout' => 5,
'redirection' => 5,
'httpversion' => '1.0',
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ),
'blocking' => true,
'headers' => array(),
'cookies' => array(),
'body' => null,
'compress' => false,
'decompress' => true,
'sslverify' => true,
'stream' => false,
'filename' => null
);
投稿者 muuming : 2020年09月28日 09:43