【发布时间】:2013-01-30 14:26:45
【问题描述】:
我正在尝试在 Wordpress 中的模板代码中创建自定义帖子。
<div class="demo">
<?php global $user_ID;
$new_post = array(
'post_title' => 'My New Post',
'post_content' => 'Lorem ipsum dolor sit amet...',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
);
$post_id = wp_insert_post($new_post); ?>
</div>
这似乎没有在页面上显示帖子?
【问题讨论】:
-
我在我的 index.php 文件中添加了这个。我是否需要将其添加到函数中,然后从 index.php 中调用它?
-
您在执行
$post_id = wp_insert_post($new_post, true); var_dump($post_id);时是否收到有用的错误消息? -
别介意,我误解了你的问题。
-
如何让它显示帖子?