WordPress ajax problem need wordpress expert?

The answer is quite simple – you are not giving admin-ajax what it is expecting. Please refer to the source code http://core.trac.wordpress.org/browser/tags/3.2.1/wp-admin/admin-ajax.php#L17 if ( ! isset( $_REQUEST[‘action’] ) ) die(‘-1’); So make sure you are giving it an action (which you are not). Then, a little lower there is: if ( ! $id ) die(‘-1’); … Read more

Convert this relative path to absolute

As long as your wp-admin directory is still at the root of your site, you can just add a forward slash (/) to the URI. Alterntaively, you can use wp_localize_script() to pass in your site’s URL or, if you are using WordPress’s AJAX functions, the ajaxurl JS variable. var ajaxPath=”/wp-admin/admin-ajax.php”; Or <?php wp_enqueue_script( ‘some_handle’ ); … Read more

Three level taxonomy dropdown frontend

After spending many hours using google I managed to make 3-level hierarchical taxonomy dropdown with ajax. Here is my code: searchform.php <script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js” ></script> <script type=”text/javascript”> $(function(){ $(‘#apskritis’).change(function(){ var $apskritisSlug=$(‘#apskritis’).val(); // call ajax $(“#savivaldybe”).empty(); $(“#miestas_kaimas”).empty(); $.ajax({ url:”/wp-admin/admin-ajax.php”, type:’POST’, data:’action=get_savivaldybes&apskritis_slug=’ + $apskritisSlug, success:function(results) { //alert(results); $(“#savivaldybe”).removeAttr(“disabled”); $(“#savivaldybe”).append(results); } }); } ); $(‘#savivaldybe’).change(function(){ var $savivaldybeSlug=$(‘#savivaldybe’).val(); // … Read more

Load ajax if is_home()

Use: if ( is_home() or ( defined( ‘DOING_AJAX’ ) && DOING_AJAX ) ) is_home() returns TRUE on the front-end only, admin-ajax.php on the other hand is an admin page. So you need to check both conditions.