
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);
セットアップしててコンピューター名つけ忘れてどこかわからなくなったとき
コマンドプロンプトから
nbtstat -R #キャッシュをクリア
nbtstat -a コンピューター名
nbtstat- c
で出てくる
インストール覚書
perlがインストールされてる環境(64bit版 v5.26.3)
PAR::Packerをインストールする
cpan install PAR::Packer
エラーが出る
よくわからんけどwindres.exeがC:\Perl64\binにないかららしい
ここ(C:\Perl64\site\lib\auto\MinGW\bin)にあるのでコピーしてここ(C:\Perl64\bin)に貼り付ける
再度 cpan install PAR::Packer
C:\Perl64\site\bin\dmake.exe install — OK
と出てインストール完了
使い方
pp -M モジュール名 -M モジュール名 パス\スクリプト.pl -o ほげほげ.exe
※20/16追記
文字コードがUnicodeだとなぜか下のエラーが出る
C:\Perl64\site\bin/pp: Binary ‘ほげほげ.pl’ sure doesn’t smell like perl source!
C:\Perl64\site\bin/pp: Please try a perlier file!
とりあえずshift-jisにして回避する
function.phpに以下を追加
//記事の並び順
function my_orderby_post_date( $query ) {
if( $query->is_main_query() ) {
if( $query->is_home() || $query->is_category() ) {
$query->set( 'order', 'desc' );
$query->set( 'orderby', 'post_date' );
}
}
}
add_action( 'pre_get_posts', 'my_orderby_post_date' );
XML-RPCの機能を使う
IXR_Library.phpを使う
<?php
include_once("IXR_Library.php");
$client = new IXR_Client("https://xxx.com/xmlrpc.php");
$wp_username = "namae";
$wp_password = "password";
$status = $client->query(
"wp.newPost", //使うAPIを指定(wp.newPostは、新規投稿)
1, //ブログID 通常は1、マルチサイトの場合は変更が必要
$wp_username, //ユーザー名
$wp_password, //パスワード
array(
"post_author" => 1, //投稿者ID 未指定の場合、投稿者名なしになります
"post_status" => "future", //投稿状態
"post_title" => "これはテスト投稿ですphp", //タイトル
"post_content" => "テスト投稿本文です。", //本文
"terms" => array("category" => array(1)) //カテゴリ
)
);
if(!$status){
die("エラー! - ".$client->getErrorCode()." : ".$client->getErrorMessage());
} else {
$post_id = $client->getResponse(); //返り値は投稿ID
}
プラグインのTinyMCE Advancedが入ってる環境
設定で

こうする
管理画面の外観のテーマエディターでfunction.phpに以下を追加する
add_action( 'restrict_manage_posts', 'add_author_filter' );
function add_author_filter() {
wp_dropdown_users( array(
'show_option_all' => 'すべてのユーザー',
'name' => 'author'
) );
}