Load posts via AJAX without draft status

admin-ajax.php is treated as part of the admin, so protected statuses will be included. To solve this just explicitly define post_status as publish to only get published posts: $args = array( ‘post_type’ => ‘project’, ‘post_status’ => ‘publish’ ); Or, better yet, consider using the REST API for AJAX requests, instead of the aging admin-ajax.php approach. … Read more

How to handle Ajax Calls, when using same shortcodes (with different parameters, e.g. ‘post-type’)?

The problem is that your JS needs to know the post type for each shortcode, but rather than looking at the shortcodes output, it looks at the main global kne_ajax_object, and since there is only one kne_ajax_object, there can only be one post type. Additionally, your javascript code only runs one time, and only makes … Read more

Bad Request 400… jQuery ajax post of json data to wordpress admin-ajax.php

To elaborate on my comments, your issue is here: contentType: ‘application/json; charset=utf-8’, data: JSON.stringify({ action: ‘cdnjs_add_library’, library: library }), When sending data to admin-ajax.php you need to set the action property of data to the action name, eg. cdnjs_add_library. That’s not what you’re doing here. data is not an object with an action property, as … Read more