diff --git a/inc/inc.php b/inc/inc.php index ceb9ea6..f38f029 100644 --- a/inc/inc.php +++ b/inc/inc.php @@ -122,7 +122,7 @@ function search_filter_page($query) { } return $query; } -add_filter('pre_get_posts','search_filter_page'); +//add_filter('pre_get_posts','search_filter_page'); /** * 去除wordpress前台顶部工具条 @@ -480,12 +480,14 @@ function include_post_types_in_search($query) { } return $query; } -add_action('pre_get_posts', 'include_post_types_in_search'); +//add_action('pre_get_posts', 'include_post_types_in_search'); + /** * 让搜索支持自定义字段 */ -add_action('posts_search', function($search, $query){ +//add_action('posts_search', 'include_custom_fields_in_search',2,2); +function include_custom_fields_in_search ($search, $query){ global $wpdb; if ($query->is_main_query() && !empty($query->query['s'])) { @@ -496,7 +498,7 @@ function include_post_types_in_search($query) { $search .= $wpdb->prepare($sql, $like); } return $search; -},2,2); +}; function format_url($url){ if($url == '') @@ -511,33 +513,47 @@ function format_url($url){ } } -// 分页代码 -function pagination($query_string){ - global $posts_per_page, $paged; - $my_query = new WP_Query($query_string ."&posts_per_page=-1"); - $total_posts = $my_query->post_count; - if(empty($paged))$paged = 1; - $prev = $paged - 1; - $next = $paged + 1; - $range = 2; // only edit this if you want to show more page-links - $showitems = ($range * 2)+1; - - $pages = ceil($total_posts/$posts_per_page); - if(1 != $pages){ - echo "\n"; + return $join; +} + +/** + * 在wordpress查询代码中加入自定义字段值的查询。 + */ +add_filter('posts_where', 'cf_search_where'); +function cf_search_where( $where ) { + if(is_admin()) + return $where; + global $pagenow, $wpdb; + if ( is_search() ) { + $where = preg_replace("/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/", + "(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where ); } + return $where; +} + +/** + * 去重 + */ +add_filter ('posts_distinct', 'cf_search_distinct'); +function cf_search_distinct($where) { + if(is_admin()) + return $where; + global $wpdb; + if ( is_search() ) { + return "DISTINCT"; } + return $where; +} - \ No newline at end of file diff --git a/inc/meta-boxes.php b/inc/meta-boxes.php index 7f62917..d7f9d61 100644 --- a/inc/meta-boxes.php +++ b/inc/meta-boxes.php @@ -121,6 +121,9 @@ function save_sites_postdata($post_id) { add_action( 'admin_footer', 'add_script_and_styles' ); function add_script_and_styles() { + // 增加位置判断 + $current_screen = get_current_screen(); + if (!is_object($current_screen) || ($current_screen->id != 'sites') || ($current_screen->post_type != 'sites')) return; echo ""; + } + if($current_screen->id == 'edit-favorites'){ + echo" + "; + } +} + diff --git a/style.css b/style.css index 7e6713c..8cd6dad 100644 --- a/style.css +++ b/style.css @@ -2,7 +2,7 @@ Theme Name:WebStack Theme URI:https://www.iowen.cn Description:by 一为!官方网站:一为忆 -Version:1.1208.1 +Version:1.1210 Author:iowen Author URI: https://www.iowen.cn/ */