以下是我的代码
我的任务是从谷歌脚本发布到Wordpress的帖子
当我尝试以下代码时,我收到了无效分配左侧的错误。 (第1行,文件"代码")
请任何人都可以帮助我
function programmatically_create_post(){
// Initialize the page ID to -1. This indicates no action has been taken.
$post_id = (-1);
// Setup the author, slug, and title for the post
$author_id = 1;
$slug = 'example-post';
$title = 'My Example Post';
// If the page doesn't already exist, then create it
if( null == get_page_by_title( $title ) ) {
// Set the post ID so that we know the post was created successfully
$post_id = wp_insert_post(
array(
'comment_status' = 'closed',
'ping_status' = 'closed',
'post_author' = $author_id,
'post_name' = $slug,
'post_title' = $title,
'post_status' = 'publish',
'post_type' = 'post'
)
);
// Otherwise, we'll stop
} else {
// Arbitrarily use -2 to indicate that the page with the title already exists
$post_id == (-2);
} // end if
} // end programmatically_create_post
add_filter( "after_setup_theme", + "programmatically_create_post" );
$post_id = programmatically_create_post()
if( -1 == $post_id || -2 == $post_id ) {
// The post wasn't created or the page already exists
} // end if