there is an add to favorites button on my single post page. These records are recorded in the wp_postmeta table as follows.
| meta_id | post_id | meta_key | meta_value |
|---|---|---|---|
| 27685 | 2036 | _favorites | , 1,2,3 |
| 27686 | 2035 | _favorites | , 2,4,5 |
How can I get how many times the active single post page has been favorited.
It is necessary to count 1,2,3 values in meta_value, but I couldn't find any results how to get it.
With this code, I can get the favorite posts of the logged in user. But I couldn't figure out how to use it on single post page.
$sql=$wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_type = %s and post_author='%d' and post_status IN ('publish','pending','draft' ) ",$directory_url,$current_user->ID );
$authpr_post = $wpdb->get_results($sql);
$total_post=count($authpr_post);
$iv_redirect_user = get_option( '_profile_public_page');
$reg_page_user='';
if($iv_redirect_user!='defult'){
$reg_page_user= get_permalink( $iv_redirect_user) ;
}
if($total_post>0){
$i=0;
foreach ( $authpr_post as $row )
{
$user_list= get_post_meta($row->ID,'_favorites',true);
$user_list_arr2 = array();
$user_list_arr = array_filter( explode(",", $user_list), 'strlen' );
$i=0;
foreach($user_list_arr as $arr){
if(trim($arr)!=''){
$user_list_arr2[$i]=$arr;
$i++;
}
}
if(sizeof($user_list_arr2)>0){
$args_users = array ('include' =>$user_list_arr2,);
$user_query = new WP_User_Query( $args_users );
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
}
}
}
}
}