dongpai2754 2015-12-23 08:33
浏览 45

使用一些WordPress函数更新元框值。 可能?

Question: Is it possible to update the meta box value of a WordPress post using some function like we do with update_post_meta()?

Explanation: Here is the format of the data saved in database for the metabox I want to update with a function/hook. enter image description here

Now, if I want to update just a single entry from that data, let say 'start_year' then how can I do that using a function/hook?

If I choose to go with update_post_meta(65, '_mycpt_date', ''2010), it will obviously replace everything with just '2010'.

  • 写回答

1条回答 默认 最新

  • douzhen5158 2015-12-23 08:51
    关注

    After doing a bit of brainstorming and with the help of this I did it with a little bit of workaround.

    // Storing the value/array in the variable.
       $options = get_post_meta( 65, '_chronos_date', true);
    
    // Updating the new value using key-value pair. That way, other parts of the array would remain un-touched.
      $options['start_year']= "2000";
    
    // Update the new value.
    update_post_meta(65,'_chronos_date',$options);
    

    It was quick. I hope it'd help someone else.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用