javascript - 自动触发 Wordpress 帖子中的“更新”按钮
问题描述
我正在为 Wordpress 使用Modern Events Calendar插件,并且通过Distributor插件将事件从一个站点推送到另一个站点(不是多站点!) 。推送事件时,直到我手动点击推送事件中的“更新”按钮,才会创建 mec_events 和 mec_dates 表的数据库条目。据我所知,条目被推送为 post meta,然后在点击更新按钮时转换为 db 条目。
或者换句话说:事件类型帖子的更新按钮触发了我需要发生的事件插件中的东西,我无法找出究竟需要发生什么,因为插件非常复杂。所以我的想法是找到一种方法来实际按下更新按钮来自动触发我需要的一切。肮脏,我知道,但对我来说似乎是“简单的出路”。事件导入非常好,并且在事件中手动使用更新按钮后一切都正确。只是我不想每次都为每个事件手动执行此操作。
如何触发手动使用更新按钮时发生的相同事情,但通过代码/php?
(显然我已经尝试过 wp_update_post 等,将事件作为草稿推送,然后通过代码发布,但这些都不会触发我需要事件插件执行的操作,因此从 post meta 创建数据库条目。只有可怕的大蓝色按钮可以。)
EDIT1:我尝试过的非常简单的例子是这样的(在推动草稿之后):
// Publish post 37
$post = array(
'ID' => 37,
'post_status' => 'publish',
);
// Update the post into the database
wp_update_post( $post );
我认为这(或 wp_insert_post 或 save_post)会触发更新按钮的所有挂钩,但无济于事。
EDIT2:在使用以下代码更改元数据后,我现在确定 wp_update_post 不会触发所需的操作。
function change_postmeta(){
$args = array(
'post_type' => 'mec-events',
'post_status' => 'publish',
'posts_per_page' => -1
);
$posts = get_posts( $args );
foreach($posts as $p) :
$meta = get_post_meta($p->ID, 'mec_start_date',true);
echo "<script>console.log('POST IDs: " . json_encode($p->ID) . "');</script>";
if($meta) :
$my_post = array();
$my_post['ID'] = $p->ID;
$my_post['post_content'] = $meta . "works!" . $p->post_content ;
// Update the post into the database
wp_update_post( $my_post );
unset($my_post);
//remove the meta key
delete_post_meta($p->ID, 'mec_start_date');
endif;
endforeach;
}
使用它可以将事件开始日期成功打印到内容并保存,但它不会触发手动更新帖子时发生的相同事情。而且我还没有找到一种方法来找出实际上与蓝色按钮相关联的内容。
解决方案
推荐阅读
- java - 我在 NetBeans 中看不到或编辑 MySQL 存储过程
- xml - Python 使用 xmltodict 解析 xml 文件并将其添加到列表中
- rest - 如何在rest api中直接在JPA级别获取用户信息
- php - Laravel 5.7 - 将项目转移到现场时无法运行 php artisan 命令
- abap - 通过任意 ABAP 变量选择选项
- python - 覆盖函数装饰器参数
- bash - 图案中的退化位置-bash
- podio - Podio WebHooks RequestBin 测试
- c# - 函数 GET 和 POST 上的 C# SQL Server CLR 请求错误
- python - Python2 vs Python3:从时间戳转换为日期时间时的不同结果