Skip to content

Instantly share code, notes, and snippets.

@kurudrive
Last active November 25, 2025 06:32
Show Gist options
  • Select an option

  • Save kurudrive/67e4bfc2f221b6d214632998e3451776 to your computer and use it in GitHub Desktop.

Select an option

Save kurudrive/67e4bfc2f221b6d214632998e3451776 to your computer and use it in GitHub Desktop.
Change Publish Status
<?php
/**
* Plugin Name: Change Publish Status
* Description: 特定の記事名の公開状態を非公開から公開に変更するプラグイン
* Version: 1.0.0
* Author: Vektor,Inc.
*
* @package ChangePublish
*/
// WordPress 以外からの直接アクセスを防止.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action(
'load-index.php', // 管理画面のダッシュボードが表示されるタイミングで実行
function () {
// 変更したい記事のタイトルを指定 **********************
$title = '公開状態を変更する記事のタイトル';
$query = new WP_Query(
array(
'post_type' => 'any',
'post_status' => array( 'private' ),
'title' => $title,
'posts_per_page' => 1,
'no_found_rows' => true,
)
);
if ( $query->have_posts() ) {
$post = $query->posts[0];
wp_update_post(
array(
'ID' => $post->ID,
'post_status' => 'publish',
)
);
}
wp_reset_postdata();
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment