Changeset 1083667
- Timestamp:
- 02/06/2015 09:12:19 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
opensearchserver-search/trunk/opensearchserver_admin.php
r1083265 r1083667 108 108 } 109 109 //Add custom fields schema 110 $custom_field_labels = opensearchserver_get_ all_custom_fields();110 $custom_field_labels = opensearchserver_get_selected_custom_fields(); 111 111 foreach($custom_field_labels as $custom_field_label => $key) { 112 $check_custom_field_label = 'oss_custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)); 113 if(get_option($check_custom_field_label)==1) { 114 opensearchserver_setField($schema,$schema_xml,'custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)),'TextAnalyzer','yes','yes','no','yes','no'); 115 opensearchserver_setField($schema,$schema_xml,'custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)).'_notAnalyzed',NULL,'no','yes','yes','yes','no'); 116 } 117 } 112 opensearchserver_setField($schema,$schema_xml,$custom_field_label,'TextAnalyzer','yes','yes','no','yes','no'); 113 opensearchserver_setField($schema,$schema_xml,$custom_field_label.'_notAnalyzed',NULL,'no','yes','yes','yes','no'); 114 } 118 115 /* 119 116 * action "oss_create_schema" … … 168 165 } 169 166 } 170 $custom_field_labels = opensearchserver_get_all_custom_fields(); 171 foreach($custom_field_labels as $custom_field_label => $key) { 172 $check_custom_field_label = 'oss_custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)); 173 if(get_option($check_custom_field_label)==1) { 174 $query_template->setReturnField('search','custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label))); 175 $query_template->setReturnField('search','custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)).'_notAnalyzed'); 176 } 167 $custom_field_labels = opensearchserver_get_selected_custom_fields(); 168 foreach($custom_field_labels as $custom_field_label => $key) { 169 $query_template->setReturnField('search',$custom_field_label); 170 $query_template->setReturnField('search',$custom_field_label); 177 171 } 178 172 } … … 454 448 455 449 // Handling custom fields 456 $custom_field_labels = opensearchserver_get_ all_custom_fields();450 $custom_field_labels = opensearchserver_get_selected_custom_fields(); 457 451 foreach($custom_field_labels as $custom_field_label => $key) { 458 $check_custom_field_label = 'oss_custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)); 459 if(get_option($check_custom_field_label)==1) { 460 $field = trim($custom_field_label); 452 $field = str_replace('oss_custom_field_','',trim($custom_field_label)); 461 453 $custom_content = ''; 462 454 $custom_values=get_post_custom_values($field, $post->ID); … … 468 460 $custom_content = $custom_values; 469 461 } 470 $document->newField( 'custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)), $custom_content);471 $document->newField( 'custom_field_'.strtolower(str_replace(' ', '_', $custom_field_label)).'_notAnalyzed', $custom_content);472 }462 $document->newField($custom_field_label, $custom_content); 463 $document->newField($custom_field_label.'_notAnalyzed', $custom_content); 464 473 465 } 474 466 … … 816 808 update_option('oss_enable_translation_wpml', $oss_enable_translation_wpml); 817 809 } 810 811 812 function opensearchserver_get_selected_custom_fields() { 813 global $wpdb; 814 $selected_custom_fields = array(); 815 $custom_fields = array(); 816 $selected_custom_fields = $wpdb->get_col("SELECT option_name FROM wp_options WHERE option_name LIKE 'oss_custom_field%' AND option_value=1"); 817 if ($selected_custom_fields){ 818 natcasesort($selected_custom_fields); 819 } 820 foreach ($selected_custom_fields as $key => $value) { 821 $custom_fields[$value] = 1; 822 } 823 return $custom_fields; 824 } 825 826 818 827 function opensearchserver_get_all_custom_fields() { 819 $args = array( 820 'post_status' => array('publish','draft','pending','future'), 821 'post_type' => 'any', 822 'posts_per_page' => -1, 823 ); 824 $allposts = get_posts($args); 825 foreach ( $allposts as $post ) : setup_postdata($post); 826 $post_id = $post->ID; 827 $fields = get_post_custom_keys($post_id); 828 if ($fields) { 829 foreach ($fields as $key => $value) { 830 if ($value[0] != '_') { 831 $custom_fields[$value] = isset($custom_fields[$value]) ? $custom_fields[$value] + 1 : 1; 832 } 833 } 834 } 835 endforeach; wp_reset_postdata(); 836 return $custom_fields; 828 global $wpdb; 829 $meta_keys = array(); 830 $custom_fields = array(); 831 $meta_keys = $wpdb->get_col("SELECT meta_key FROM $wpdb->postmeta GROUP BY meta_key HAVING meta_key NOT LIKE '\_%' ORDER BY meta_key"); 832 if ($meta_keys){ 833 natcasesort($meta_keys); 834 } 835 foreach ($meta_keys as $key => $value) { 836 $custom_fields[$value] = isset($custom_fields[$value]) ? $custom_fields[$value] + 1 : 1; 837 } 838 return $custom_fields; 837 839 } 838 840
Note: See TracChangeset
for help on using the changeset viewer.