Incrementing PHP variable onclick to display posts by month

Try registering a function handling ajax calls first. // For logged out users add_action( ‘wp_ajax_nopriv_wp280265_pagination’, ‘wp280265_pagination’ ); // For logged in users add_action( ‘wp_ajax_wp280265_pagination’, ‘wp280265_pagination’ ); Define the function. function wp280265_pagination() { $month = $_POST[‘month’]; $year = $_POST[‘year’]; if ($month != ” && $year != ”) get_posts($month, $year); } Define JavaScript. (function($) { $(document.body).on(‘click’, ‘#previous’, … Read more

passing values from functions.php to template

You could get your get_publications functions to return a JSON object with all sorts of information you need. e.g function get_publications() { // Your query here. $data = [ ‘html’ => $your_html, ‘found_posts’ => $query->found_posts, ‘current_post’ => $query->current_post, ‘current_page’ => $page, etc… ]; echo json_encode($data); } And then parse that data with your javascript.

WP_Query with AJAX returning empty array

$response->status, $response->query etc. is not how you set array values in PHP. So you’re just returning that empty array you defined at the beginning. To set a value on an array use square brackets and string for the key: $response[‘status’] = true; Do that everywhere you currently have ->. Also, if you can get the … Read more

Call current post URL in ajax

you can retrieve the permalink of the current post in JavaScript with wp_localize_script. juste try this code after the call of wp_enqueue_script wp_localize_script( “script_id” , “object” , [ “permalink” => get_post_permalink($post), ] ); and then you can read the permalink in JavaScript in object[“permalink”]

Admin-ajax php not working on new wordpress version

I previously thought that the issue was ajax/javascript related but it only seemed that way because the ajax script was not receiving any data. After inspection I saw that my query was returning 0 values. It turned out to be an issue of wp_queries breaking when using meta_query combined with the repeater format of Advanced … Read more

processing form data with ajax

This way to insert data in db using AJAX works for me. Hope this help you. Function scripts function add_our_script() { wp_register_script( ‘ajax-js’, get_template_directory_uri() . ‘/scripts/keeled.js’, array( ‘jquery’ ), ”, true ); wp_localize_script( ‘ajax-js’, ‘ajax-js_ajax’, array( ‘ajax_url’ => admin_url( ‘admin-ajax.php’ ) ) ); } add_action( ‘wp_enqueue_scripts’, ‘add_our_script’ ); Template Form: <form> <label for=”nimi”>Nimi</label> <input name=”nimi” … Read more

Asynchronous request in wordpress

Your AJAX URL varaible is different in your PHP and your JS. In your JS you refer to ajax_url: url: modallist.ajax_url, But the variable defined in PHP is ajaxurl: ‘ajaxurl’ => admin_url(‘admin-ajax.php’) , This is why you’re getting the full admin page as a response. Your request is going to the current page because there … Read more