dozc1071 2014-11-03 07:00 采纳率: 100%
浏览 97

Wordpress:在wordpress外添加自定义字段时不显示

I have a requirement that needs to me to create posts with some custom fields from outside of Wordpress

I have been able to add the post, necessary custom fields from outside using standard WP functions.

I can also see the entries in postmeta and posts table.

But, these values are not available to me in the frontend where I want to display them. However when I open this post in the dashboard's write panel, I see that all the values are filled correctly and if I just update it, the values start appearing in the front end.

I'm sure I'm missing out something here. So, any help is much appreciated.

Below is the code I'm using currently to achieve the above

$post = array(

  'post_name'      => 'g-test-3', // The name (slug) for your post
  'post_title'     => 'G Testing 3', // The title of your post.
  'post_status'    => 'publish', // Default 'draft'.
  'post_type'      =>  'post',// Default 'post'.
  'post_author'    =>  5090,// The user ID number of the author. Default is the current user ID.
  'post_excerpt'   => '', // For all your post excerpt needs.
  'post_date'      =>  date('Y-m-d H:i:s'),  // The time post was made.
  'comment_status' => 'open', // Default is the option 'default_comment_status', or 'closed'.
  'post_category'  => array(644)// Default empty.
);  

$posted =  wp_insert_post( $post, true );
echo 'post id: '. $posted;
$added = array();
$added[]= update_post_meta($posted, 'external_url', 'http://example.com/external-url', false);
$added[]= update_post_meta($posted, 'media', 'Yes', false);
$added[]= update_post_meta($posted, 'remarks', 'These are the example remarks', false);
$added[]= update_post_meta($posted, 'alternate_headline', 'Alternate headline for G Testing', false);
$added[]= update_post_meta($posted, '_mf_write_panel_id', '13', false);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮