Wordpress 自定义帖子 [英] Wordpress custom post

查看:42
本文介绍了Wordpress 自定义帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Wordpress 模板的代码中创建自定义帖子.

 

<?php 全局 $user_ID;$new_post = 数组('post_title' =>'我的新帖子','post_content' =>'Lorem ipsum dolor 坐...','post_status' =>'发布','post_date' =>date('Y-m-d H:i:s'),'post_author' =>$user_ID,'post_type' =>'邮政','post_category' =>数组(0));$post_id = wp_insert_post($new_post);?>

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

解决方案

 

<?php 全局 $user_ID;$new_post = 数组('post_title' =>'我的新帖子','post_content' =>'Lorem ipsum dolor 坐...','post_status' =>'发布','post_date' =>date('Y-m-d H:i:s'),'post_author' =>$user_ID,'post_type' =>'邮政','post_category' =>数组(0));$post_id = wp_insert_post($new_post);?>

上面代码的作用是插入一个新帖子.阅读更多

<块引用>

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

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

<?php get_post( $post_id );?>

阅读更多

I'm trying to create custom posts in the code of my template in 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>

This doesn't seem to display the post on the page?

解决方案

 <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); ?>

What above code does is insert a new post. Read more

This doesn't seem to display the post on the page?

What you are trying to do here is inserting a new post. if you want that post to be shown try the below code

<?php get_post( $post_id ); ?>

Read more

这篇关于Wordpress 自定义帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆