{"id":6993,"date":"2025-07-09T13:41:11","date_gmt":"2025-07-09T04:41:11","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=6993"},"modified":"2025-08-01T13:59:28","modified_gmt":"2025-08-01T04:59:28","slug":"post-6993","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/6993","title":{"rendered":"WordPress\u3067\u69cb\u7bc9\u3055\u308c\u305f\u30b5\u30a4\u30c8\u5185\u3067Ajax\u901a\u4fe1\u3092\u884c\u3046\u65b9\u6cd5"},"content":{"rendered":"<p>WordPress\u3067\u69cb\u7bc9\u3055\u308c\u305f\u30b5\u30a4\u30c8\u5185\u3067\u30dc\u30bf\u30f3\u30af\u30ea\u30c3\u30af\u6642\u7b49\u306bAjax\u901a\u4fe1\u3092\u884c\u3044\u305f\u3044\u3068\u3044\u3046\u30b1\u30fc\u30b9\u304c\u3042\u3063\u305f\u3002\u9069\u5f53\u306a\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u51e6\u7406\u7528\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u8a2d\u7f6e\u3057\u3001\u305d\u3061\u3089\u306b\u5bfe\u3057\u3066\u30ea\u30af\u30a8\u30b9\u30c8\u3057\u3066\u3082\u6b63\u5e38\u306b\u52d5\u4f5c\u305b\u305a\u3001\u4f55\u6545\u306a\u306e\u304b\u8abf\u3079\u305f\u3068\u3053\u308dWordPress\u7528\u306e\u304a\u4f5c\u6cd5\u307f\u305f\u3044\u306a\u306e\u304c\u3042\u308b\u3089\u3057\u3044\u3002\u4ee5\u4e0b\u306b\u5bfe\u5fdc\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u5bfe\u5fdc\u65b9\u6cd5<\/h2>\n<h3>Ajax\u9001\u4fe1\u5074<\/h3>\n<p>Ajax\u9001\u4fe1\u3057\u305f\u3044\u30da\u30fc\u30b8(\u30d5\u30a1\u30a4\u30eb)\u306b\u4ee5\u4e0b\u3092\u8a18\u8ff0\u3059\u308b\u3002<\/p>\n<p><a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/admin_url\/\" target=\"_blank\" rel=\"noopener\">admin_url()<\/a>\u306fWordPress\u7528\u95a2\u6570\u306b\u306a\u308b\u304c\u3001\u3053\u308c\u3092\u4f7f\u3044\u305f\u304f\u306a\u3044(JS\u30d5\u30a1\u30a4\u30eb\u3067\u5b8c\u7d50\u3055\u305b\u305f\u3044\u3088\u3046\u306a)\u5834\u5408\u306f\u300c\/wordpress\/wp-admin\/admin-ajax.php\u300d\u306e\u3088\u3046\u306b\u9069\u5b9c\u5909\u66f4\u3059\u308b\u3053\u3068\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">$(document).on(`click`, `.button`, function(){\r\n    $.ajax({\r\n        url: `&lt;?php echo admin_url(\"admin-ajax.php\")?&gt;`, \/\/admin-ajax.php\u306b\u5bfe\u3057\u3066\u9001\u4fe1(\u3053\u3053\u306f\u56fa\u5b9a)\r\n        type: 'POST',\r\n        data: {}, \/\/\u4f55\u3089\u304b\u306e\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3059\u308b\u5834\u5408\u306f\u3053\u3061\u3089\u3067\u6307\u5b9a\r\n    }).done(function( result ){\r\n\r\n    }).fail(function() {\r\n\r\n    }).always(function() {\r\n\r\n    });\r\n\r\n    return false;\r\n});<\/pre>\n<h3>\u53d7\u4fe1\u5074<\/h3>\n<p>functions.php\u7b49\u306b\u4ee5\u4e0b\u3092\u8a18\u8ff0\u3059\u308b\u3002<a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/wp_ajax_action\/\" target=\"_blank\" rel=\"noopener\">wp_ajax_{$action}<\/a>\u306f\u30ed\u30b0\u30a4\u30f3\u6e08\u307f\u30e6\u30fc\u30b6\u30fc\u3001<a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/wp_ajax_nopriv_action\/\" target=\"_blank\" rel=\"noopener\">wp_ajax_nopriv_{$action}<\/a>\u306f\u672a\u30ed\u30b0\u30a4\u30f3\u306e\u30e6\u30fc\u30b6\u30fc\u306b\u3088\u308bAjax\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306e\u30d5\u30c3\u30af\u306b\u306a\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function ajax_function(){\r\n    \/\/\u4f55\u3089\u304b\u306e\u51e6\u7406\r\n\r\n    \/\/\u5024\u3092\u8fd4\u3057\u305f\u3044\u5834\u5408\u306fecho\u3067\u51fa\u529b\r\n    echo $result;\r\n\r\n    \/\/\u7d42\u4e86\u3055\u305b\u308b\r\n    wp_die();\r\n}\r\nadd_action( 'wp_ajax_ajax_function', 'ajax_function' );\r\nadd_action( 'wp_ajax_nopriv_ajax_function', 'ajax_function' );<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9<\/h2>\n<h3>admin_url<\/h3>\n<p><a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/admin_url\/\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.wordpress.org\/reference\/functions\/admin_url\/<\/a><\/p>\n<h3>do_action( \"wp_ajax_{$action}\" )<\/h3>\n<p><a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/wp_ajax_action\/\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.wordpress.org\/reference\/hooks\/wp_ajax_action\/<\/a><\/p>\n<h3>do_action( \"wp_ajax_nopriv_{$action}\" )<\/h3>\n<p><a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/wp_ajax_nopriv_action\/\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.wordpress.org\/reference\/hooks\/wp_ajax_nopriv_action\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress\u3067\u69cb\u7bc9\u3055\u308c\u305f\u30b5\u30a4\u30c8\u5185\u3067\u30dc\u30bf\u30f3\u30af\u30ea\u30c3\u30af\u6642\u7b49\u306bAjax\u901a\u4fe1\u3092\u884c\u3044\u305f ... <\/p>\n","protected":false},"author":1,"featured_media":1093,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[24,41],"tags":[],"class_list":["post-6993","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","category-cms"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=6993"}],"version-history":[{"count":1,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6993\/revisions"}],"predecessor-version":[{"id":6994,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6993\/revisions\/6994"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1093"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=6993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=6993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=6993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}