Created
January 3, 2017 17:37
-
-
Save moshfiqur/0d820d568aff50240ff4bc0a6b12493c to your computer and use it in GitHub Desktop.
Programmatically create post category for wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Guessing this script is placed in the root wordpress directory. | |
// If not, change the require_once statements script path accordingly. | |
require_once('wp-load.php'); | |
require_once('wp-admin/includes/taxonomy.php'); | |
$conn = new mysqli('localhost', 'username', 'password', 'database'); | |
if ($conn->connect_error) { | |
die('Connection failed'); | |
} | |
$result = $conn->query("SELECT category FROM table"); | |
if ($result->num_rows > 0) { | |
while($row = $result->fetch_assoc()) { | |
wp_create_category($row['category'], 0); // 0 is no parent category | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment