我目前正在以编程方式创建一篇文章,其中wp_insert_post
函数,但在将两个变量添加到数组的内容部分时遇到了一些困难。我想补充一下$_POST[\'poll-description\']
以及我目前使用的代码\'[poll id=\' . $latest_pollid . \']\'
成为帖子内容。
在下面的代码中,我是否可以同时使用这两种方法?
$post_id = wp_insert_post(
array(
\'comment_status\' => \'open\',
\'ping_status\' => \'closed\',
\'post_author\' => $current_user->ID,
\'post_name\' => $slug,
\'post_title\' => $pollq_question,
\'post_status\' => \'publish\',
\'post_type\' => \'post\',
\'post_content\' => \'[poll id=\' . $latest_pollid . \']\'
)
);
这样行吗?
`post_content\' => $_POST[\'poll-description\'] \'[poll id=\' . $latest_pollid . \']\'`
最合适的回答,由SO网友:Omar Tariq 整理而成
$post_id = wp_insert_post(
array(
\'comment_status\' => \'open\',
\'ping_status\' => \'closed\',
\'post_author\' => $current_user->ID,
\'post_name\' => $slug,
\'post_title\' => $pollq_question,
\'post_status\' => \'publish\',
\'post_type\' => \'post\',
\'post_content\' => $_POST[\'poll-description\'] . \'[poll id=\' . $latest_pollid . \']\'
)
);
SO网友:WPTC-Troop
只需将发布的描述和您的短代码结合起来,然后将其插入到帖子中即可。
$concat_content = $_POST[\'poll-description\'].\'[poll id="\' . $latest_pollid . \'"]\';
$post_id = wp_insert_post(
array(
\'comment_status\' => \'open\',
\'ping_status\' => \'closed\',
\'post_author\' => $current_user->ID,
\'post_name\' => $slug,
\'post_title\' => $pollq_question,
\'post_status\' => \'publish\',
\'post_type\' => \'post\',
\'post_content\' => $concat_content
)
);
如果您发现上述内容令人困惑,请尝试以下内容
$concat_content = $_POST[\'poll-description\'];
$concat_content .= \'[poll id="\' . $latest_pollid . \'"]\';
您甚至可以在内容和短代码之间插入一个中断标记