Php 使用AJAX和onclick批量更新Post-Meta
我想在单击时将wp_查询中的posts元值更新为不同的值。我基本上是在做一个通知气泡(比如stackoverflow)Php 使用AJAX和onclick批量更新Post-Meta,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我想在单击时将wp_查询中的posts元值更新为不同的值。我基本上是在做一个通知气泡(比如stackoverflow) wp_查询具有元值“未读”的帖子数-正在工作 在登录用户的显示名称-工作的顶部op上显示计数气泡 单击通知后,隐藏气泡并使用ajax将wp_查询中的帖子的post meta value从“未读”更改为“已读”,以便只有在出现具有meta value“未读”的新帖子时,计数才可见-如何 显示所有最新帖子的下拉列表,其中的元值为“read”-可能是另一个查询 这是我计算泡泡数的代码
add_shortcode('notify', 'notify_member');
function notify_member() {
global $current_user;
get_currentuserinfo();
$userid = $current_user->ID;
$args = array(
'posts_per_page' => '-1',
'post_type' => 'answer',
'post_status' => 'publish',
'author__not_in' => $userid, //exclude user posts
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'question_owner_id'
'value' => $userid, //only show posts for the user
'compare' => '='
),
array(
'key' => '_read_answer'
'value' => 'unread', //only show unread posts
'compare' => '='
),
)
);
$questions = new WP_Query( $args );
$html = '';
$html .= '<a href="#" class="count">'.$questions->found_posts.'</a>'; //total count
return $html;
}
我没有主意,任何方向都欢迎。谢谢另外,我不是编码员,所以请解释一下。也许能帮上忙,谢谢。我会根据我的要求进行调整,然后再回复你。我现在有了一个工作结构。谢谢。这个答案对我也有帮助。谢谢@brasofilo
if( $questions->have_posts() ) {
while ( $questions->have_posts() ) { $questions->the_post();
update_post_meta( $post->ID, '_read_answer', 'read' );
}
}