Wordpress:使用wp_insert_post()在帖子中插入帖子格式 [英] Wordpress: insert post-format in post using wp_insert_post()

查看:142
本文介绍了Wordpress:使用wp_insert_post()在帖子中插入帖子格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我可以使用wp_insert_post()使用帖子的格式(例如post -format- quote)插入我的php帖子.

as I can insert my php post using the format of a post ( example : post -format- quote ) using wp_insert_post ().

$my_post = array(
    'post_type'     => 'post', // "post" para una entrada, "page" para páginas, "libro" para el custom post type libro...
    'post_status'   => 'publish', // "draft" para borrador, "future" para programarlo...
    'post_title'    => $_POST['BlogEntranceTitle'], 
    'post_content'  => $_POST['BlogEntranceCode'], 
    'post_author'   => $user_ID, //  
    'post_category' => $_POST['BlogEntranceCats'],  
    'tags_input'    => $_POST['BlogEntranceTags'],
    'post_excerpt'  => $_POST['BlogEntranceExcerpt']
);
wp_insert_post( $my_post );

成就插入这些选项,但是我没有添加格式的帖子

achievement insert these options but I get no add format post

推荐答案

您需要单独更新帖子格式,因为帖子格式是一种分类法.请参见以下示例,以更新帖子格式.

You need to update post format separately because Post Format is a type of taxonomy. See following example for updating post format.

$my_post = array(
'post_type'     => 'post', // "post" para una entrada, "page" para páginas, "libro"     para el custom post type libro...
    'post_status'   => 'publish', // "draft" para borrador, "future" para programarlo...
    'post_title'    => $_POST['BlogEntranceTitle'], 
    'post_content'  => $_POST['BlogEntranceCode'], 
    'post_author'   => $user_ID, //  
    'post_category' => $_POST['BlogEntranceCats'],  
    'tags_input'    => $_POST['BlogEntranceTags'],
    'post_excerpt'  => $_POST['BlogEntranceExcerpt']
);
$new_post_id  = wp_insert_post( $my_post );
$tag = 'post-format-image';
$taxonomy = 'post_format';
wp_set_post_terms( $new_post_id, $tag, $taxonomy );

插入帖子后,将返回帖子ID.该ID用于更新帖子格式.在上面的示例中,将分配Image帖子格式.请根据您的要求进行更改.

After inserting Post, Post ID is returned. That ID is used to update the post format. In the above example, Image post format will be assigned. Please change it as per your requirement.

这篇关于Wordpress:使用wp_insert_post()在帖子中插入帖子格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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