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 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题