Bad Request when adding new post via ajax form

Finally found the problem. The action: save_post was missing from data in ajax call. This code works: <script> jQuery( document ).ready(function() { jQuery(‘input[type=button]’).on(‘click’, function() { var ajaxurl = “<?php echo admin_url(‘admin-ajax.php’); ?>”; jQuery.ajax({ type: “POST”, data: { data:jQuery(‘.event-form’).serialize(), action: ‘save_post’ }, url: ajaxurl, success: function(result) { console.log(‘data sent!’); console.log(‘sent to: ‘ + templateDir + loadUrl … Read more

Plugin Admin Page Ajax-Admin call returning 0, URL set correctly. Implemented localized scripts but did not fix it

Hi please try below code jquery : $(‘#saveMediaButton’).click(function(e) { e.preventDefault(); $.ajax({ url : my_ajax_object.ajax_url, type : ‘post’, data : { action : ‘action_upload_img’, image_attachment_id : document.getElementById(“image-preview”).getAttribute(‘src’) }, dataType : ‘html’, success : function( response ) { var jsonData = response; console.log(response); console.log(document.getElementById(“image-preview”).getAttribute(‘src’)); }, error : function(jqxhr, textStatus, errorThrown) { console.log(my_ajax_object.ajax_url); console.log(jqxhr); console.log(textStatus); console.log(errorThrown); }, }); … Read more

custom form submission

You can’t use admin-post.php directly in your form, you need implement an ajax request. https://codex.wordpress.org/AJAX_in_Plugins To send your email have a function wp_mail https://developer.wordpress.org/reference/functions/wp_mail/ If you have problem to receive the POST params review this answer WordPress AJAX with Axios

Categories as selectable links on submission form

Once you retrieved your categories, let’s say in $categories, you can do something like this: <?php foreach ($categories as $catgory) { ?> <form id=”cat-button-form-<?php echo $category->ID; ?>” action=”<?php echo $url_to_step_2; ?>” method=”POST”> <input type=”hidden” name=”mycat” value=”<?php echo $category->ID; ?>” /> <input type=”submit” name=”getcat” id=”getcat_<?php echo $category->ID; ?>” class=”btn_catstep” value=”<?php printf(__(‘Select %s &amp; Continue’), $category->name); ?>” … Read more

How to go to tag archives using a form

To understand how to do it you first need to know how the url query works or more specifically what query vars you need, so: ‘post_type’ – to filter by post types. ‘area’ – to filter by area taxonomy. ‘university’ – to filter by university taxonomy. so your url would look like: // http://www.domain.com/?post_type=properties&area=area_term&university=university_term Now … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)