Questions tagged «wp-update-post»


2
如何避免save_post回调中的无限循环
我一直在使用这个网站来解决我的问题,但是这次我没有成功找到并回答我的问题。 wp_update_post在调用on的函数内部使用时,出现无限循环save_post。我知道这是一个普遍的问题,但是我不知道该如何避免。 我想保存帖子的顺序(属于帖子类型“部分”)。因此,我制作了一个自定义元框,其中包含一些可排序的html元素。在每个元素中都有一个名称为'sectionorder []'的隐藏输入标签。因此,当我单击标准WordPress“更新”按钮时,包含所有帖子ID的数组(按顺序)是通过POST发送的。所以这是我检索数组并想要保存顺序的代码: // Update section sort order $sectionorder = $_POST['sectionorder']; if (isset($sectionorder)) { // Avoid error if there is no sections added yet foreach( $sectionorder as $no => $sectionID ) { $post_update = array(); $post_update['ID'] = $sectionID; $post_update['menu_order'] = $no; wp_update_post( $post_update ); } } 但是问题在于它开始了无限循环。如何避免这种情况?也许我可以用完全不同的方式来做? 寻求您的帮助!
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.