-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter for Post Status #21
Comments
Sure, you could mimic what the plugin is doing w/ the post-types: /**
* Hook into pre_get_posts if we're doing a cmb2_post_search ajax request.
*/
function cmb2_post_search_check_if_ajax_post_search() {
if (
defined( 'DOING_AJAX' )
&& DOING_AJAX
&& isset( $_POST['cmb2_post_search'], $_POST['action'] )
&& 'find_posts' == $_POST['action']
) {
add_action( 'pre_get_posts', 'cmb2_post_search_set_post_status' );
}
}
add_action( 'admin_init', 'cmb2_post_search_check_if_ajax_post_search' );
/**
* Set the post status via pre_get_posts
* @param array $query The query instance
*/
function cmb2_post_search_set_post_status( $query ) {
$query->set( 'post_status', 'publish' );
} |
Justin - this is great. Thank you! |
👍 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any possibility of filtering based on status? It would be nice to eliminate drafts in my current use case. Thanks!
The text was updated successfully, but these errors were encountered: