title: Calling a function after a click on a button in Wordpress (dev-plugin)
body: <p>This is my code and I wanna do what is commented near line 73 (//HOW CAN I CALL FUNCTION post_type_search_callback HERE???). The results need to be in the same page, below the "form". I was trying some tutorials about ajax in the web but without succeeded. Pls help! Thanks!</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  
  class OwnersTriplify {
  
   const plugin_name = 'Owners-triplify';
  
   public static function head() {
  
   }
  
   public static function initialize() {
  
    add_action('admin_menu', 'owners_triplify_admin_actions');
  
    function owners_triplify_admin_actions() {
    
    add_menu_page('Owners Triplify', 'Owners Triplify', 'manage_options', 'owners-triplify/includes/OwnersTriplify.php', 'owners_triplify', plugins_url('owners-triplify/images/icon.png'));
    
    }
  
    function register_my_setting() {
    
    register_setting( 'hd-group', 'hd_options'); 
   
    }
  
    add_action( 'admin_init', 'register_my_setting' );
  
    add_action( 'admin_enqueue_scripts', 'post_type_search_enqueue' );
  
    function post_type_search_enqueue($hook) {
         
     if( 'index.php' != $hook ) {
   
      // Only applies to dashboard panel
      return;
         }
          
     wp_enqueue_script( 'ajax-script', plugins_url( '/js/post_type_search_query.js', __FILE__ ), array('jquery') );
     
     // in JavaScript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value
     
     wp_localize_script( 'ajax-script', 'ajax_object',
              
     array( 'ajax_url' =&gt; admin_url( 'admin-ajax.php' ), 'we_value' =&gt; 1234 ) );
    }
  
    function owners_triplify() {
  
     ?&gt;
  
     &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
     &lt;script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"&gt;&lt;/script&gt;
  
     &lt;div id="div1"&gt;
  
      &lt;h3&gt;Digite o post-type que deseja triplificar: &lt;/h3&gt;
      &lt;br/&gt;
       &lt;form method="post" name="form1" action=""&gt;
        &lt;input name="postType" value="" id="postType"&gt;
        &lt;input type="hidden" name="action" value="update"&gt;
        &lt;input type="hidden" name="option_page" value="hd_options"&gt;
        &lt;button id="button1" name="termoPesquisado" type="submit" class="button-primary"&gt;Pesquisar&lt;/button&gt;
       &lt;/form&gt; 
      &lt;br/&gt;
  
     &lt;/div&gt;
  
     &lt;script&gt;
  
      $("#button1").click(function () {
  
       //HOW CAN I CALL FUNCTION post_type_search_callback HERE???
  
      });
  
      /*$("#button1").click(function () {
  
       if ( $("#div2").is( ":hidden" ) ) {
        
        $("#div2").slideDown();
        
        $("#div1").hide();
  
        } 
  
        else {
        
        }
  
      });*/
  
     &lt;/script&gt;
  
    &lt;?php
  
    }
  
    function pegaValores($data) {
  
     $data = trim($data);
     $data = stripslashes($data);
     $data = htmlspecialchars($data);
     return $data;
  
    }
  
    $termo = pegaValores($_POST["postType"]);
  
    ?&gt;
  
    &lt;?php
  
    add_action('wp_ajax_post_type_search', 'post_type_search_callback');
  
    function post_type_search_callback() {
  
     ?&gt;
  
     &lt;div id="div2"&gt;
  
     &lt;h3&gt;Digite as equivalências: &lt;/h3&gt;
  
     &lt;?php
  
     global $wpdb;
     $resultado = $wpdb-&gt;get_results("SELECT distinct meta_key FROM $wpdb-&gt;postmeta WHERE post_id in(SELECT ID FROM $wpdb-&gt;posts WHERE post_type = '".$termo."')");
     $correspondencias;
     $tamanhoResultado = count($resultado);
     
     for($i = 1; $i &lt;= $tamanhoResultado; $i++) {
  
      $correspondencias[$i] = "correspondencia";
  
     }
     
     $contador = 1;
  
     //$resultado_array = array();
  
     foreach($resultado as $resultadoX) {
  
      echo "&lt;p&gt;". 
      $resultado_array[] = $contador."- ".$resultadoX-&gt;meta_key." =&gt; ".
      "&lt;input value=".$correspondencias[$contador]." id='correspondencia".$contador."'/&gt;".
      "&lt;/p&gt;"; //descobrir como colocar $contador + 1 para imprimir, a fim de que inicialize com 0 o contador e o for do correspondencias
      
      $contador++;
  
      //$datacount = implode('-',$resultado_array);
  
      ?&gt;
  
     &lt;?php
  
     }
  
     ?&gt;
  
     &lt;button id="button2" name="triplify" onclick="atualizaValores()" class="button-primary" &gt;Triplificar&lt;/button&gt;
  
     &lt;/div&gt;
  
    &lt;?php
  
    }
  
  
   }
  
  }
  
  ?&gt;</code></pre>
  </div>
  </div>
  </p>