Autocomplete Search: Post Status
-
*Note: This post refers to version 1.3 of CPT-onomies (http://plugins.svn.wordpress.org/cpt-onomies/tags/1.3/).
I am using an autocomplete relation with cpt-onomies an I was asked to include items that are in draft. I looked through the code hoping to find a filter or action I could easily use to set what status are searched. No such luck.
The function “ajax_meta_box_autocomplete_callback” starting on line 409 of admin.php (http://plugins.svn.wordpress.org/cpt-onomies/tags/1.3/admin.php) shows this (on line 416 within the function):$available_terms = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_title AS label, post_parent AS parent FROM " . $wpdb->posts . " WHERE post_type = %s AND post_status = 'publish' ORDER BY post_title ASC", $taxonomy ) );
So it appears the post_status of ‘publish’ is hard-coded into the query.
🙁I recommend the following changes (to admin.php):
// Add before line 415: $post_status = array_walk( apply_filter( 'custom_post_type_onomies_autocomplete_post_status', array( 'publish' ) ), array( $wpdb, '_real_escape' ) ); // Replace line 416 (line number is prior to adding 415): $available_terms = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_title AS label, post_parent AS parent FROM " . $wpdb->posts . " WHERE post_type = %s AND post_status IN ('" . implode("','", $post_status) . "') ORDER BY post_title ASC", $taxonomy ) );
And an example of using the filter:
function my_custom_cponomies_autocomplete_post_status( $post_status_array ) { // Include drafts in search: $post_status_array[] = 'draft'; return $post_status_array; } add_filter( 'custom_post_type_onomies_autocomplete_post_status', 'my_custom_cponomies_autocomplete_post_status' );
- The topic ‘Autocomplete Search: Post Status’ is closed to new replies.