如果我知道 post ID,我可以将 WordPress 草稿转换为带有直接 link 的已发布 post 吗?
Can I turn a WordPress Draft into a published post with a direct link if I know the post ID?
例如,使用这样的函数:
http://website.com/wp-admin/post.php?post=%%post_id%%&action=publish
P.S。我检查了一下,这不起作用,但我想知道是否有类似的东西在精神上起作用?
您可以将此代码粘贴到您的主题 functions.php
文件中。这将达到目的,现在如果您将操作参数更改为 draft
并发送一个获取请求,它将生成 post 草稿。
add_action( 'admin_init', 'draft_post_status_221' );
function draft_post_status_221(){
// Get current page , so this action will only fire in post.php page.
global $pagenow;
if ( $pagenow != 'post.php' ){
return;
}
$post_id = false;
$action = false;
// get post id
if ( isset($_GET['post']) && !empty($_GET['post']) ){
$post_id = $_GET['post'];
}
// get action
if ( isset($_GET['action']) && !empty($_GET['action']) ){
$action = $_GET['action'];
// for security we only allow draft action
if ( $action != 'draft' ){
$action = false;
}
}
// if $post_id and $action has data than post will be updated.
if ( !empty($post_id) && !empty($action) ){
$args = array(
'ID' => $post_id,
'post_status' => $action
);
wp_update_post( $args );
}
}
例如,使用这样的函数:
http://website.com/wp-admin/post.php?post=%%post_id%%&action=publish
P.S。我检查了一下,这不起作用,但我想知道是否有类似的东西在精神上起作用?
您可以将此代码粘贴到您的主题 functions.php
文件中。这将达到目的,现在如果您将操作参数更改为 draft
并发送一个获取请求,它将生成 post 草稿。
add_action( 'admin_init', 'draft_post_status_221' );
function draft_post_status_221(){
// Get current page , so this action will only fire in post.php page.
global $pagenow;
if ( $pagenow != 'post.php' ){
return;
}
$post_id = false;
$action = false;
// get post id
if ( isset($_GET['post']) && !empty($_GET['post']) ){
$post_id = $_GET['post'];
}
// get action
if ( isset($_GET['action']) && !empty($_GET['action']) ){
$action = $_GET['action'];
// for security we only allow draft action
if ( $action != 'draft' ){
$action = false;
}
}
// if $post_id and $action has data than post will be updated.
if ( !empty($post_id) && !empty($action) ){
$args = array(
'ID' => $post_id,
'post_status' => $action
);
wp_update_post( $args );
}
}