search-extras.php
3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
add_action( 'add_attachment', 'add_attachment_mime_type' );
function add_attachment_mime_type( $attachment_id ){
$post = get_post( $attachment_id );
$post_mime_type = explode(".", $post->_wp_attached_file);
update_post_meta( $attachment_id, 'file_type', end($post_mime_type) );
}
function wptp_add_tags_to_attachments() {
register_taxonomy_for_object_type( 'post_tag', 'attachment' );
}
add_action( 'init' , 'wptp_add_tags_to_attachments' );
function filter_query_args( $query_args, $sfid ) {
error_log(print_r($query_args,true));
//$query_args['posts_per_page'] = -1;
//$query_args['orderby'] = 'relevance';
//$query_args['order'] = 'ASC';
return $query_args;
}
add_filter( 'sf_edit_query_args', 'filter_query_args', 99, 2 );
function relevant_search_result( $q ) {
if ( is_search() && is_main_query() )
$q->set( 'orderby', 'relevance');
$q->set( 'order', 'ASC');
}
//add_action( 'pre_get_posts', 'relevant_search_result' );
add_action('init','set_exclude_from_search');
function set_exclude_from_search()
{
if ($_GET['var'] =='set_wpml_from_search') {
global $post;
$args = array( 'posts_per_page' => -1, 'post_type' => 'documents');
$pages = get_posts( $args );
error_log(print_r($pages,true));
foreach ( $pages as $page ){
error_log($page->ID);
update_post_meta($page->ID, 'wpml', "EN" );
}
$args = array( 'posts_per_page' => -1, 'post_type' => 'attachment');
$pages = get_posts( $args );
error_log(print_r($pages,true));
foreach ( $pages as $page ){
error_log($page->ID);
update_post_meta($page->ID, 'wpml', "EN" );
}
}
}
add_action('init','delete_exclude_from_search');
function delete_exclude_from_search()
{
if ($_GET['var'] =='delete_wpml_from_search') {
$args = array( 'posts_per_page' => -1, 'post_type' => 'attachment');
$pages = get_posts( $args );
foreach ( $pages as $page ){
$exclude_from_search = get_post_meta($page->ID, 'exclude_from_search', true);
if($exclude_from_search == '0'){
wp_update_post(get_post( $page->ID) );
//error_log($page->ID);
}
}
}
}
add_action('init','update_tax_counts');
function update_tax_counts()
{
if ($_GET['var'] =='update_tax_counts') {
include("wp-config.php");
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD)) { die('Could not connect: ' . mysqli_error()); }
if (!mysqli_select_db($conn,DB_NAME)) { die('Could not connect: ' . mysqli_error()); }
$result = mysqli_query($conn, "SELECT term_taxonomy_id FROM ".$table_prefix."term_taxonomy");
while ($row = mysqli_fetch_array($result)) {
$term_taxonomy_id = $row['term_taxonomy_id'];
echo "term_taxonomy_id: ".$term_taxonomy_id." count = ";
$countresult = mysqli_query($conn, "SELECT count(*) FROM ".$table_prefix."term_relationships WHERE term_taxonomy_id = '$term_taxonomy_id'");
$countarray = mysqli_fetch_array($countresult);
$count = $countarray[0];
echo $count."<br>";
mysqli_query($conn, "UPDATE ".$table_prefix."term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term_taxonomy_id'");
}
}
}