Skip to content

Instantly share code, notes, and snippets.

@moshfiqur
Created January 3, 2017 17:37
Show Gist options
  • Save moshfiqur/0d820d568aff50240ff4bc0a6b12493c to your computer and use it in GitHub Desktop.
Save moshfiqur/0d820d568aff50240ff4bc0a6b12493c to your computer and use it in GitHub Desktop.
Programmatically create post category for wordpress
<?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