WordPress AJAX Basics
-
I just read through a free 300 page book WordPress & AJAX by Ronald Huereca and I learned a lot but the examples are WAY out there and super advanced, plus they’re pointed in very specific directions that I cannot use or adapt… Lame.
Can I have some help getting this basic AJAX query to work?// page-test.php
<div id="my_search"> <form role="search" method="post" id="searchform" action="" > <input type="text" value="" name="s" id="s" /> <input type="submit" id="searchsubmit" value="Search" /> </form> </div> <div id="results"></div> <script type="text/javascript"> $(document).ready(function(){ $("#searchsubmit").click(function(e){ e.preventDefault(); var search_val=$("#s").val(); $.ajax({ type:"POST", url: "./wp-admin/admin-ajax.php", data: { action:'wpa56343_search', search_string:search_val }, success:function(data){ $('#results').append(response); } }); }); </script> <strong>// end page-test.php</strong> <strong>// functions.php</strong> add_action('wp_ajax_nopriv_wpa56343_search', 'wpa56343_search'); // for not logged in users add_action('wp_ajax_wpa56343_search', 'wpa56343_search'); function wpa56343_search(){ global $wp_query; $search = $_POST['search_val']; $args = array('post_type' => 'post_type'); $wp_query = new WP_Query( $args ); exit; }
I can’t get over how difficult AJAX in WordPress is. Any advice on creating a basic function to build my queries in would be AWESOME.
Thanks.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘WordPress AJAX Basics’ is closed to new replies.