How to prevent action in ajax request, when in admin side?


I have a plugin that hides certain posts in the frontend. For this to be consistent, I need posts to also be hidden in searches and AJAX searches (needs to work with any theme and search).

To make this work with AJAX search, I am using:

if ( wp_doing_ajax() ){
    add_action( 'pre_get_posts', array($this, 'plugin_function_set_visibility') );

My only problem is, this also hides the posts in the admin dashboard, posts can no longer be edited.

is_admin() does not work in this situation, it returns true for any admin-ajax request

, , , , Mike J 2 years 2020-09-01T04:10:18-05:00 0 Answers 50 views 0

Leave an answer