【发布时间】:2016-11-14 14:53:30
【问题描述】:
我有会员网站,用户必须付费订阅。当用户订阅时,他的角色成为“成员”,现在可以发布到名为“user-profile”的自定义帖子类型
如果例如用户角色更改为“已过期”,我想要做的是在此帖子类型中将所有已发布帖子的状态更改为待处理
我试过了,但似乎没有任何效果
function auto_expire_posts(){
global $wpdb, $wp_roles;
//get all post ids of published posts.
$post_ids = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_status = 'publish' ");
foreach($post_ids as $id){
$postid = $id->ID;
if ($_GET['role'] == "expired" )
{
$profile_post = array();
$profile_post['ID'] = $postid;
$profile_post['post_status'] = 'pending';
// Update the post into the database
wp_update_post( $profile_post );
}
}
}
add_action('set_user_role', 'auto_expire_posts');
【问题讨论】:
-
您还需要在查询中选择
post_status列。 -
wordpress 会员插件
-
我正在使用重力表单并手动管理订阅,如果我手动更改角色以获得结果,我想要
-
SELECT ID, post_status FROM $wpdb->posts -
@Fred-ii- 所以它应该看起来像这样:
$post_ids = $wpdb->get_results( "SELECT ID, post_status FROM $wpdb->posts" );