Monthly Archives

4 Articles

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
}