why is my wordpress Jquery-Ajax call not working?

You need to change the data that you are sending in the ajax request. For ajax to work in WordPress you need to send the action variable in ajax post request. Change data: {package: package}, to data: {action: ‘ajaxAutopopulate’, package: package} Also you can use the wordpress default function wp_send_json( $response ) for encoding of … Read more

Adding srcset to an image in ajax

wp_get_attachment_image_srcset is the key here: wp_get_attachment_image_srcset( int $attachment_id, array|string $size=”medium”, array $image_meta = null ) I believe the missing information you lack, is that post thumbnails are actually an attachment ID. In combination with get_post_thumbnail_id you should be able to generate srcset values. But also keep in mind that while googling, every question I found … Read more

Full Front End, AJAX comment system and comment reply script

<script> var addComment = { settings: function( parentId, postId ) { var t = $(this), commentDivName = $(‘#comment-‘+parentId), formDivName = $(‘#commentForm-‘+postId), formReplyDivName = $(‘#commentReplyForm-‘+parentId), postDivName = $(‘#post-‘+postId), theform = formDivName.find(‘form.comment-form’); if( !t.length || !commentDivName.length || !formDivName.length || !postDivName.length ) { return; } if(!theform.length){ $(postDivName).find(‘[id^=commentReplyForm-]’).each(function(){ if($(this).find(‘form.comment-form’).length){ formDivName = $(‘#’+$(this).attr(‘id’)); } }); theform = formDivName.find(‘form.comment-form’); } theform.find(‘input[name=parent]’).val(parentId); … Read more

pass wordpress template directory into ajax url call

I suspect you don’t want to hardcode your URL to data.php, but using a standalone file to handle requests in a theme or plugin is a major security problem. Instead, using a REST API endpoint. For example, lets register a data endpoint: add_action( ‘rest_api_init’, function () { register_rest_route( ‘monacoder/v1’, ‘/data/’, array( ‘methods’ => ‘POST’, ‘callback’ … Read more

Post not populating for custom post type based on category selection

But this part is not executing → $args = array( ‘category_name’ => $taxonomy, ‘post_type’ => ‘video’, ‘posts_per_page’ => -1, It probably is. It’s just wrong. If you want to query posts by terms in a custom taxonomy you need to add a taxonomy query: $args = array( ‘post_type’ => ‘video’, ‘posts_per_page’ => -1, ‘tax_query’ => … Read more

javascript variable to wordpress php variable

First you need to to send function name as additional data as $.ajax({ type: “POST”, url: compareids_ajax.ajax_url, data: { // Data object compareIDs : compareIDs, action: ‘your_ajax_function’ // This is required to let WordPress know which function to invoke }, contentType: “application/json; charset=utf-8”, dataType: “json”, success: function (msg) { console.log( msg ); }, error: function … Read more