如何删除或减少自定义字段值-1

时间:2015-11-30 08:40:45

标签: wordpress custom-fields

我的wordpress网站功能文件中有以下功能

function setVideoHalfViews() {
  global $wpdb;
  if (!isset($_POST['data'])) {
    exit;
  }
  $data = json_decode(stripslashes_deep($_POST['data']), true);
  $halfViewsCount = $data['halfViewsCount'];
  $currentPostId = $data['currentPostId'];
  $count_key = 'halfViewsCount';
  $viewsMeta = get_post_meta($currentPostId, $count_key, true);
  $count_keydeletepartial = 'partialViewsCount';
  $viewsMetadeletepartial = get_post_meta($currentPostId, $count_keydeletepartial, true);
  if ($viewsMeta == '') {
    add_post_meta($currentPostId, $count_key, $halfViewsCount, true);
  } else {
    $viewsMeta++;
    update_post_meta($currentPostId, $count_key, $viewsMeta);
    --$viewsMetadeletepartial;
  }

  $count_key2 = 'wrdp_half_fs';
  $viewsMeta2 = get_post_meta($currentPostId, $count_key2, true);
  if ($viewsMeta2 == '') {
    add_post_meta($currentPostId, $count_key2, $videoViewsCount, true);
  } else {
    $viewsMeta2++;
    update_post_meta($currentPostId, $count_key2, $viewsMeta2);
  }

}

我想通过此代码将$ viewsMetadeletepartial自定义字段值减少-1 - $ viewsMetadeletepartial。但它似乎不起作用。知道为什么吗?我尝试使用$ viewsMetadeletepartial--但也有相同的结果。

0 个答案:

没有答案