Add flag counter in views Module(Search API index) I want to add flag counter of content in views field. Authenticated users can flag(bookmark) contents. I want to know how many users flaged a content, And I want to add this in views field(display the number of times a node is flagged by a certain flag by Users).

Notice; I'm using "Search API Index" in content part of views

How can I do it?



UPDATE Question after using Vicky8888 method;

I added below code in global php field of views

   &lt;?php
   $flag = flag_get_flag('bookmarks');
   if ($flag) {
  print "Number of Flags:";
  print $flag-&gt;get_count($node-&gt;nid);
      }
    ?&gt;


this code work in tpl.php file of content type, But It's showing "0" in views.
I got several errors in picture too.



after that I using JS code of Vicky8888.

Drupal.behaviors.your-theme = {

 attach: function (context, settings) { 

 //add your available class below
    jQuery('.view-id-top_users.view-display-id-page .views-field-php .flag-link-toggle').click(function(){

        jQuery(document).ajaxComplete(function() {
         location.reload();
        });
       });
      }
       };


I cleared "your-theme" and added "adaptivetheme", and cleared classes and added 
".view-content .views-field.views-field-php .field-content .flag-link-toggle". 

after that I using this code in separate file and added 

scripts[]=scripts/extracode.js


in adaptivetheme.info file.

I cleared cache and run cron too.
but It didn't work too.
Use these two modules drupal like and flag simultaneously

Go to /admin/structure/flags create flag ,and  configure it properly.

Go to your view add  Global: PHP field

 &lt;?php
print flag_create_link('bookmarks',$node-&gt;nid);

 $counts = flag_get_counts('node', $node-&gt;nid);
if(isset($counts['bookmarks'])){
 echo $counts['bookmarks'] .' Likes';
 }else{
      echo"no user flaged a content";
     }


 ?&gt;


And at last put this code in your themes js file

Drupal.behaviors.your-theme = {

 attach: function (context, settings) { 

 //add your available class below
    jQuery('.view-id-top_users.view-display-id-page .views-field-php .flag-link-toggle').click(function(){

        jQuery(document).ajaxComplete(function() {
         location.reload();
        });
       });
      }
       };


To add the flag link in your content type use code:

   &lt;?php
    global $user ,$base_url;
    if(!$user-&gt;uid) {
   $flag_link = flag_flag_link($flag, $action, $content_id);


   $flag_url = $flag_link['href'];
    if(isset($flag_link['query']['token'])) {

    $flag_url .= '?'.$flag_link['query']['token'];
}

?&gt;

  &lt;a href="&lt;?php echo $base_url;?&gt;/user/login?destination=&lt;?php echo      current_path();?&gt;"&gt;MY-LINK&lt;/a&gt;