Category Archives

13 Articles

wordpressの投稿を外部から取得する

Posted on

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);

 

windows10でperlスクリプトをexe化

Posted on

インストール覚書

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にして回避する

pixel3XL買った

Posted on

iphone11にがっかりでpixelが安くなってたから

https://onlineshop.smt.docomo.ne.jp/information/notice/20190905_01.html

カメラが良い
左がiphoneX 右がpixel3XL

ag-beerag-taiyoag-moo

pixelの方が解像してる
大きさはでかくなったけど薄い
重さは10グラムくらい増えた
OSはiOSのほうがぬるぬるしてて良い
pixelは待ち受け状態でも時計が表示されて良い

wordpressで記事の表示順を公開日順にする

Posted on

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' );

 

wordpressに外部から投稿する

Posted on

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
}