dqbh8054 2011-02-04 18:25
浏览 35

WP插入PHP函数和自定义字段

The wordpress function is used for submitting data programatically. Standard fields to submit to incude the content, excerpt, title, date and many more.

What there is no documentation for is how to submit to a custom field. I know it is possible with the add_post_meta($post_id, $meta_key, $meta_value, $unique); function.

What I don't know is how to include that into the standard wp_insert_post function. So the reason I ask you all is because this is more of a PHP question than a WP question. Below is the PHP code to submit the post.

<?php 
$my_post = array(
     'post_title' => $_SESSION['booking-form-title'],
     'post_date' => $_SESSION['cal_startdate'],
     'post_content' => 'This is my post.',
     'post_status' => 'publish',
     'post_type' => 'booking',
  );
  wp_insert_post( $my_post );
  ?>

Any help chaps,

Marvellous

  • 写回答

1条回答 默认 最新

  • dsfdsf21312 2011-02-04 21:16
    关注

    If you look at the functions reference in the codex, you can see that wp_insert_post returns The ID of the post if the post is successfully added to the database.

    Because of that, you can do so:

    <?php 
    
    $my_post = array(
        'post_title' => ...
    );
    
    $new_post_id = wp_insert_post( $my_post );
    
    add_post_meta($new_post_id, $meta_key, $meta_value, $unique);
    
    ?>
    

    Hope this helps

    评论

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?