0
이것은 내 코드이며 73 행 근처에 주석을 달고 싶습니다 (post_type_search_callback 여기에 함수를 호출 할 수 있습니까?). 결과는 "양식"아래의 동일한 페이지에 있어야합니다. 웹에서 아약스에 대한 튜토리얼을 시도했지만 성공하지 못했습니다. Pls 도움! 감사! 귀하의 모든 기능을 선언하는Wordpress에서 버튼을 클릭 한 후 함수 호출하기 (dev-plugin)
<?php
class OwnersTriplify {
\t const plugin_name = 'Owners-triplify';
\t public static function head() {
\t }
\t public static function initialize() {
\t \t add_action('admin_menu', 'owners_triplify_admin_actions');
\t \t function owners_triplify_admin_actions() {
\t \t
\t \t add_menu_page('Owners Triplify', 'Owners Triplify', 'manage_options', 'owners-triplify/includes/OwnersTriplify.php', 'owners_triplify', plugins_url('owners-triplify/images/icon.png'));
\t \t
\t \t }
\t \t function register_my_setting() {
\t \t
\t \t register_setting('hd-group', 'hd_options');
\t
\t \t }
\t \t add_action('admin_init', 'register_my_setting');
\t \t add_action('admin_enqueue_scripts', 'post_type_search_enqueue');
\t \t function post_type_search_enqueue($hook) {
\t \t \t
\t \t \t if('index.php' != $hook) {
\t
\t \t \t \t // Only applies to dashboard panel
\t \t \t \t return;
\t \t \t }
\t \t \t wp_enqueue_script('ajax-script', plugins_url('/js/post_type_search_query.js', __FILE__), array('jquery'));
\t \t \t
\t \t \t // in JavaScript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value
\t \t \t
\t \t \t wp_localize_script('ajax-script', 'ajax_object',
\t \t \t array('ajax_url' => admin_url('admin-ajax.php'), 'we_value' => 1234));
\t \t }
\t \t function owners_triplify() {
\t \t \t ?>
\t \t \t <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
\t \t \t <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
\t \t \t <div id="div1">
\t \t \t \t <h3>Digite o post-type que deseja triplificar: </h3>
\t \t \t \t <br/>
\t \t \t \t \t <form method="post" name="form1" action="">
\t \t \t \t \t \t <input name="postType" value="" id="postType">
\t \t \t \t \t \t <input type="hidden" name="action" value="update">
\t \t \t \t \t \t <input type="hidden" name="option_page" value="hd_options">
\t \t \t \t \t \t <button id="button1" name="termoPesquisado" type="submit" class="button-primary">Pesquisar</button>
\t \t \t \t \t </form> \t
\t \t \t \t <br/>
\t \t \t </div>
\t \t \t <script>
\t \t \t \t $("#button1").click(function() {
\t \t \t \t \t //HOW CAN I CALL FUNCTION post_type_search_callback HERE???
\t \t \t \t });
\t \t \t \t /*$("#button1").click(function() {
\t \t \t \t \t if ($("#div2").is(":hidden")) {
\t \t \t \t \t \t
\t \t \t \t \t \t $("#div2").slideDown();
\t \t \t \t \t \t
\t \t \t \t \t \t $("#div1").hide();
\t \t \t \t \t \t }
\t \t \t \t \t \t else {
\t \t \t \t \t \t
\t \t \t \t \t \t }
\t \t \t \t });*/
\t \t \t </script>
\t \t <?php
\t \t }
\t \t function pegaValores($data) {
\t \t \t $data = trim($data);
\t \t \t $data = stripslashes($data);
\t \t \t $data = htmlspecialchars($data);
\t \t \t return $data;
\t \t }
\t \t $termo = pegaValores($_POST["postType"]);
\t \t ?>
\t \t <?php
\t \t add_action('wp_ajax_post_type_search', 'post_type_search_callback');
\t \t function post_type_search_callback() {
\t \t \t ?>
\t \t \t <div id="div2">
\t \t \t <h3>Digite as equivalências: </h3>
\t \t \t <?php
\t \t \t global $wpdb;
\t \t \t $resultado = $wpdb->get_results("SELECT distinct meta_key FROM $wpdb->postmeta WHERE post_id in(SELECT ID FROM $wpdb->posts WHERE post_type = '".$termo."')");
\t \t \t $correspondencias;
\t \t \t $tamanhoResultado = count($resultado);
\t \t \t
\t \t \t for($i = 1; $i <= $tamanhoResultado; $i++) {
\t \t \t \t $correspondencias[$i] = "correspondencia";
\t \t \t }
\t \t \t
\t \t \t $contador = 1;
\t \t \t //$resultado_array = array();
\t \t \t foreach($resultado as $resultadoX) {
\t \t \t \t echo "<p>".
\t \t \t \t $resultado_array[] = $contador."- ".$resultadoX->meta_key." => ".
\t \t \t \t "<input value=".$correspondencias[$contador]." id='correspondencia".$contador."'/>".
\t \t \t \t "</p>"; //descobrir como colocar $contador + 1 para imprimir, a fim de que inicialize com 0 o contador e o for do correspondencias
\t \t \t \t
\t \t \t \t $contador++;
\t \t \t \t //$datacount = implode('-',$resultado_array);
\t \t \t \t ?>
\t \t \t <?php
\t \t \t }
\t \t \t ?>
\t \t \t <button id="button2" name="triplify" onclick="atualizaValores()" class="button-primary" >Triplificar</button>
\t \t \t </div>
\t \t <?php
\t \t }
\t }
}
?>
감사 남자, 이해하지만 지금 난 오류가있어,이 : "형식 오류 : $ 아약스는 함수가 아닙니다 " –
대신 jQuery를 사용합니다. 위의 내용을 업데이트했습니다! – David