wp_ajax add_action fuction won’t fire on custom jQuery action
wp_ajax add_action fuction won’t fire on custom jQuery action
wp_ajax add_action fuction won’t fire on custom jQuery action
Solution was simple. Set DOM element value in JS variable instead of “document.getElementById(‘post_category’).value” in array. var submitBtn = document.getElementById(‘submit-post-btn’); submitBtn.addEventListener(‘click’, function(){ var categoryTerm = document.getElementById(‘post_category’).value; var postData = { “title”: document.getElementById(‘post_title’).value, “content”: document.getElementById(‘post_content’).value, “status”: ‘publish’, “categories”: [categoryTerm] } };
Custom Post type Ajax search results
You could replace your call to wp_ajax for a custom REST endpoint. This should be useful: https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
Assuming the function hooked to the action load_posts_by_ajax is your load_posts_by_ajax_callback() code (seems a reasonable assumption), the query arguments can be easily modified. You mention “displays only 3 posts” which is what the code is designed to do. If you wish to show 10 posts, update the posts_per_page argument listed. ‘posts_per_page’ => ‘3’, The bigger … Read more
You could copy the contents of your current archive page file into a new file, then tweak the functionality there into what you need it to do. At the top of the file, give it a template name like this: /* Template Name: Short Archive */ Now you can create a new page and select … Read more
OK, so first of all – AJAX requests are separate, so you don’t have to remove_action if you haven’t added it earlier… And to be honest, I don’t really get your code – you modify the global wp_query object, but it’s really not so clear how and why is there any query created during AJAX … Read more
AJAX form not working, still reloads on submit
This will not work: function widget_data(){ include get_template_directory() . ‘/inc/wid/card/widget-card.php’; wp_die(); } The include statment includes the “widget-card.php” only into the file and not the output stream. You have to redirect the output into a variable and then output the value via “echo”. function widget_data(){ ob_start(); include get_template_directory() . ‘/inc/wid/card/widget-card.php’; $output = ob_get_clean( ); echo … Read more
My one and only idea is that when I’m inside my wp_ajax hook’d function, parsePluginInstallRequest, it simply is too early to call the install, put it this way: I don’t think so, when the wp_ajax hook is called, your class and methods are loaded. That can’t be it. Your ajax looks good, but i always … Read more