wordpressの投稿を外部から取得する
XML-RPCの機能を使う
IXR_Library.phpを使う
<?php
include_once("IXR_Library.php");
$wp_username = 'name';
$wp_password = 'password';
$siteurl = 'https://hogehoge.com/xmlrpc.php';
$filter = array(
'number' => 10, //最近の10件取得
'offset' => 0, //先頭から何件除外するか
'orderby'=> 'date', //並び順の基準
'order' => 'desc', //並び順(ASC:昇順,DESC:降順)
);
$client = new IXR_Client( $siteurl );
$status = $client->query(
"wp.getPosts", //POSTを取得する
1, // blog ID: 通常は1、マルチサイト時変更
$wp_username, // ユーザー名
$wp_password, // パスワード
$filter
);
$posts = $client->getResponse(); //arrayで戻ってくる
var_dump($posts);
