AJAX call broken after actualization

OK, I found out that my DB encoding was LATIN2 and wordpress forced UTF-8 in all calls after the update. When I changed my database’s encoding to UTF-8 it all started to work. I also used: $comment = mb_convert_encoding($comment, “UTF-8”); just to be shure.

Ajax function on #publish only saves as draft – how to make it publish?

Perhaps this solution will work: var flag_ok = false; $(‘#publish’).on(‘click’, function (e) { if ( ! flag_ok ) { e.preventDefault(); var url = shiftajax.ajaxurl; var shift = $(‘#post_ID’).val(); var data = { ‘action’: ‘wpaesm_check_for_schedule_conflicts_before_publish’, ‘shift’: shift, }; $.post(url, data, function (response) { if( response.action == ‘go’ ) { // there aren’t any scheduling conflicts, so … Read more

wp_update_post onclick button using ajax

No no no! Never POST or link directly to a custom PHP file – WordPress won’t be loaded, and to load it manually yourself means making huge assumptions about the file hierarchy. Use the ajax API, which exists specifically for this reason: $.ajax({ url: “<?php echo esc_js( admin_url( ‘admin-ajax.php’ ) ) ?>”, type: “POST”, data: … Read more

use jQuery.load() to include a php file in a div, wp_query() is part of php file

Using AJAX in WordPress is fundamentally pretty simple. You need a function that handles the AJAX request, and a couple of add_action calls to map that function to the action you pass to admin-ajax.php, in this case, some_action: function wpd_ajax_function() { get_template_part( ‘my-content’ ); wp_die(); } add_action( ‘wp_ajax_some_action’, ‘wpd_ajax_function’ ); add_action( ‘wp_ajax_nopriv_some_action’, ‘wpd_ajax_function’ ); This … Read more

Retrieve JSON file from JS trough php

I’m not convinced this is the cleanest way to do it but at least it work until I find something more efficient: function json_gmap(){ $get_file = file_get_contents(get_template_directory_uri() . ‘/data/my.json’); $json_to_array = json_decode($get_file,true); die (json_encode($json_to_array)); } add_action(‘wp_ajax_json_gmap’, ‘json_gmap’); add_action(‘wp_ajax_nopriv_json_gmap’, ‘json_gmap’); Basically I decode my Json file to an array and the re-encode it to have it … Read more

is_single() conditional check inside ajax php function

is_single returns if there is a single page displayed within the actual server process. Within the Ajax-Function, nothing is “displayed”, you’re doing Ajax. To check if the currently displayed object in your Browser is a single object, you need to transfer the information about this from the server process that serves your Browser to the … Read more