wp_ajax_find_posts [ WordPress Function ]
wp_ajax_find_posts ( No parameters )
| Defined at: |
|
Soorgelijke functies: wp_ajax_delete_post, wp_ajax_untrash_post, wp_ajax_trash_post, wp_ajax_closed_postboxes, rewind_posts
No description yet.
Source
<?php
function wp_ajax_find_posts() {
global $wpdb;
check_ajax_referer( 'find-posts' );
if ( empty($_POST['ps']) )
wp_die();
if ( !empty($_POST['post_type']) && in_array( $_POST['post_type'], get_post_types() ) )
$what = $_POST['post_type'];
else
$what = 'post';
$s = stripslashes($_POST['ps']);
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
$search_terms = array_map('_search_terms_tidy', $matches[0]);
$searchand = $search = '';
foreach ( (array) $search_terms as $term ) {
$term = esc_sql( like_escape( $term ) );
$search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
$searchand = ' AND ';
}
$term = esc_sql( like_escape( $s ) );
if ( count($search_terms) > 1 && $search_terms[0] != $s )
$search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
$posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND post_status IN ('draft', 'publish') AND ($search) ORDER BY post_date_gmt DESC LIMIT 50" );
if ( ! $posts ) {
$posttype = get_post_type_object($what);
wp_die( $posttype->labels->not_found );
}
$html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Date').'</th><th>'.__('Status').'</th></tr></thead><tbody>';
foreach ( $posts as $post ) {
switch ( $post->post_status ) {
case 'publish' :
case 'private' :
$stat = __('Published');
break;
case 'future' :
$stat = __('Scheduled');
break;
case 'pending' :
$stat = __('Pending Review');
break;
case 'draft' :
$stat = __('Draft');
break;
}
if ( '0000-00-00 00:00:00' == $post->post_date ) {
$time = '';
} else {
/* translators: date format in table columns, see http://php.net/date */
$time = mysql2date(__('Y/m/d'), $post->post_date);
}
$html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
$html .= '<td><label for="found-'.$post->ID.'">'.esc_html( $post->post_title ).'</label></td><td>'.esc_html( $time ).'</td><td>'.esc_html( $stat ).'</td></tr>'."\n\n";
}
$html .= '</tbody></table>';
$x = new WP_Ajax_Response();
$x->add( array(
'what' => $what,
'data' => $html
));
$x->send();
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- PHPXRef 0.7 : WordPress : Detail view of ajax-actions.php
wp_ajax_find_posts() wp_ajax_widgets_order() wp_ajax_save_widget() wp_ajax_upload_attachment() wp_ajax_image_editor() wp_ajax_set_post_thumbnail() ...
phpxref.ftwr.co.uk - Docs for page ajax-actions.php
/wp-admin/includes/ajax-actions.php. Description. Description | ...
phpdoc.wordpress.org - find_posts_div (WordPress Function) - WPSeek.com
Similar Functions: rewind_posts, wp_ajax_find_posts, next_posts_link, next_posts, single_post_title. {@internal Missing Short Description}} ...
wpseek.com - rewind_posts (WordPress Function) - WPSeek.com
Similar Functions: previous_posts, find_posts_div, wp_ajax_find_posts, edit_post , get_posts. Rewind the loop posts. Source. <?php function rewind_posts() { ...
wpseek.com