Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

[WP] XMLRPC를 이용한 WordPress(워드프레스) 포스트 등록 #2

2018-01-29 by 편리

지난 포스트에 이어 워드프레스 포스트 등록 자동화 과정 중 포스트 등록 때 카테고리 지정, featured image 와 태그 등을 설정할 수 있는 내용을 아래와 같이 테스트 했다.

참고 : https://codex.wordpress.org/XML-RPC_WordPress_API

<?php
require './lib/WordpressClient.php';

# Your WordPress website is at: http://wp-website.com
$endpoint = "https://exmaple.com/xmlrpc.php";

# Create client instance
$wpClient = new \HieuLe\WordpressXmlrpcClient\WordpressClient();

# Set the credentials for the next requests
$wpClient->setCredentials($endpoint, 'user id', 'user password');

$file = './files/81UM0TSMgLL._SL1500.jpg';

$name = basename($file);
$mime = mime_content_type($file);
$bits = file_get_contents($file);

# Remove .(dot) in file name
$temp = explode('.', $name);
$ext  = array_pop($temp);
$name = str_replace('.', '', implode('', $temp)) . '.' . $ext;

$media = $wpClient->uploadFile($name, $mime, $bits);

//print_r($media); exit;

if(is_array($media) && !empty($media)) {
    if(isset($media['metadata']['sizes']['large'])) {
        $imgSize = 'large';
        $width = '640';
    } else {
        $imgSize = 'medium';
        $width = $media['metadata']['sizes'][$imgSize]['width'];
    }
    
    $imgClass = 'alignnone';
    $imgSrc = $media['metadata']['sizes'][$imgSize]['file'];
    $imgSrc = str_replace($media['metadata']['sizes']['thumbnail']['file'], $media['metadata']['sizes'][$imgSize]['file'], $media['thumbnail']);
    
    $mediaLink = '<a href="'.$media['link'].'"><img class="'.$imgClass.' size-'.$imgSize.' wp-image-'.$media['attachment_id'].'" src="'.$imgSrc.'" alt="" width="'.$width.'" /></a>';

    $content = array(
        'post_thumbnail' => $media['attachment_id'],
        'terms_names' => array(
            'category' => array('그누보드5'),
            'post_tag' => array('그누보드55', '영카트5')                                    
        ),
        /*
        'custom_fields' => array(
            array('key' => '_yoast_wpseo_focuskw_text_input', 'value' => '테스트 포커스')
        )
        */
    );

    $post_content = $mediaLink;

    $post_content .= '
    테스트내용1
    
    테스트내용2';

    $post_id = $wpClient->newPost('테스트 '.$media['attachment_id'], $post_content, $content);

    $post = $wpClient->getPost($post_id);
    print_r($post);
}

Post navigation

Previous Post:

[WP] XMLRPC를 이용한 WordPress(워드프레스) 포스트 등록

Next Post:

[PHP] XMLRPC를 이용한 WordPress 포스트 등록

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • SK 세븐모바일 유심 셀프교체
  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes