-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcategory.php
73 lines (59 loc) · 1.82 KB
/
category.php
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
<?php
/*
=========================================
CONFIGURATION
=========================================
*/
$config__batch = 500;
// Category ID to assign the tweets to
$config__category_id = 2;
// Look for posts not in these categories
$config__not_in = array( 2 );
// Name of the file generated by the Twitter Archive
$config__path_import = dirname(__FILE__) . '/../wp-admin/includes/import.php';
$config__path_admin = dirname(__FILE__) . '//../wp-admin/includes/admin.php';
// Where is the WP Load located
$config__wpload_path = "../wp-load.php";
/*
=========================================
STOP RIGHT HERE
=========================================
(Unless you know what you're doing)
*/
// We are in a subfolder
include_once($config__wpload_path);
require_once $config__path_import;
require_once $config__path_admin;
echo "<pre>";
function parse_posts() {
// Calculate how much time this thing takes
$time_start = microtime(true);
global $wp_filesystem,
$wpdb,
$config__batch,
$config__category_id,
$config__not_in;
$query = new WP_Query(
array(
'posts_per_page' => $config__batch,
'category__not_in' => $config__not_in
)
);
// The Loop
if ( $query->have_posts() ) {
$counter = 0;
while ( $query->have_posts() ) {
$query->the_post();
wp_set_post_categories( get_the_ID(), array($config__category_id));
$counter++;
}
echo $counter . " posts updated.";
} else {
echo "No posts found <br><br>";
}
/* Restore original Post Data */
wp_reset_postdata();
$time_end = microtime(true);
echo "<br><br>It took me " . ($time_end - $time_start) . " seconds to do this.";
} // End of the parse_files()
parse_posts();