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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作