我有一个SQL查询,如果我直接在数据库中运行它,它可以实现我想要的功能:
UPDATE wp_pmpro_memberships_users
SET wp_pmpro_memberships_users.status = \'admin_cancelled\'
WHERE wp_pmpro_memberships_users.user_id IN
(
/*Select all users that have an active Membership but no active Subscription*/
SELECT pmpro.user_id FROM wp_pmpro_memberships_users as pmpro
JOIN wp_pmpro_membership_levels as pmprol ON pmprol.id=pmpro.membership_id
JOIN wp_users ON pmpro.user_id = wp_users.ID
WHERE pmpro.status = \'active\'
AND pmpro.user_id NOT IN
(
/*Select all users that have an active Subscription*/
SELECT meta.meta_value
FROM wp_posts as p
JOIN wp_postmeta as meta
ON meta.post_id = p.id
JOIN wp_users as u
ON meta.meta_value = u.id
WHERE post_type LIKE \'shop_subscription\'
AND post_status LIKE \'wc-active\'
AND meta.meta_key = \'_customer_user\'
)
)
并将此代码添加到我的函数中。“我的孩子”主题中的php文件:
add_action("cron_expire_nonactive_memberships", "cron_expire_nonactive_memberships");
function cron_expire_nonactive_memberships() {
global $wpdb;
$sqlQuery = "UPDATE {$wpdb->wp_pmpro_memberships_users}
SET wp_pmpro_memberships_users.status = \'admin_cancelled\'
WHERE wp_pmpro_memberships_users.user_id IN
(
/*Select all users that have an active Membership but no active Subscription*/
SELECT pmpro.user_id FROM {$wpdb->wp_pmpro_memberships_users} as pmpro
JOIN {$wpdb->wp_pmpro_membership_levels} as pmprol ON pmprol.id=pmpro.membership_id
JOIN {$wpdb->wp_users} ON pmpro.user_id = wp_users.ID
WHERE pmpro.status = \'active\'
AND pmpro.user_id NOT IN
(
/*Select all users that have an active Subscription*/
SELECT meta.meta_value
FROM {$wpdb->wp_posts} as p
JOIN {$wpdb->wp_postmeta} as meta
ON meta.post_id = p.id
JOIN {$wpdb->wp_users} as u
ON meta.meta_value = u.id
WHERE post_type LIKE \'shop_subscription\'
AND post_status LIKE \'wc-active\'
AND meta.meta_key = \'_customer_user\'
)
)";
}
但我正在尝试使用一个名为“WP Crontrol”的插件来运行它。
它有一个添加新Cron事件的选项,因此我使用了钩子cron_expire_nonactive_memberships
并且一直在手动运行,但什么都没有发生。
如果这有什么不同的话,我会以本地主机的身份运行。
我不确定尝试运行SQL的php代码是否有问题-如何调试发生的情况?
Edit:
嗯,我可以在错误日志中看到以下内容,但我不确定如何解决:
PHP Notice: Undefined property: wpdb::$wp_users in C:\\xampp\\htdocs\\myproject\\wp-includes\\wp-db.php on line 648