It seems that you’re adding the AJAX action only if $pagenow
(the current admin page/file) is edit.php
or post.php
, and that’s not going to work on admin-ajax.php
, so you should instead add the action via the admin_init
hook if you wish to add the action only on the admin side. E.g.
add_action( 'admin_init', function () {
add_action( 'wp_ajax_set_post_archived', 'set_post_archived' );
} );