【问题标题】:Wordpress custom postWordPress 自定义帖子
【发布时间】: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); 时是否收到有用的错误消息?
  • 别介意,我误解了你的问题。
  • 如何让它显示帖子?

标签: php wordpress


【解决方案1】:
 <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); ?>

上面的代码所做的是插入一个新帖子。 Read more

这似乎没有在页面上显示帖子?

您在这里尝试做的是插入一个新帖子。如果您希望显示该帖子,请尝试以下代码

<?php get_post( $post_id ); ?>

Read more

【讨论】:

  • 我需要把 '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); ?> 因为每次我刷新页面时它都会不断创建帖子。
猜你喜欢
  • 2016-11-29
  • 1970-01-01
  • 1970-01-01
  • 2013-10-10
  • 2016-12-29
  • 2019-09-06
  • 2016-07-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多