Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create project groups and project terms.
<?php
function akv3_create_projects_terms() {
$terms = array(
'commercial' => 'Commercial',
'deprecated' => 'Deprecated',
'featured' => 'Featured',
'open-source' => 'Open Source',
'wordpress' => 'WordPress',
);
foreach ($terms as $slug => $name) {
wp_insert_term($name, 'project-groups', array(
'slug' => $slug
));
}
$terms = array(
'threads' => array(
'label' => 'Threads',
'meta' => array(
'proj_github_url' => 'https://github.com/crowdfavorite/wp-threads/',
'proj_wp_url' => 'http://wordpress.org/plugins/threads/',
),
'groups' => array(
'featured',
'wordpress',
),
),
'carrington-core' => array(
'label' => 'Carrington Core',
'meta' => array(
'proj_url' => 'http://crowdfavorite.com/wordpress/carrington-core/',
'proj_github_url' => 'https://github.com/crowdfavorite/wp-carrington-core/',
),
'groups' => array(
'featured',
'wordpress',
),
),
'carrington-build' => array(
'label' => 'Carrington Build',
'meta' => array(
'proj_url' => 'http://crowdfavorite.com/wordpress/carrington-build/',
),
'groups' => array(
'featured',
'wordpress',
),
),
'sharethis' => array(
'label' => 'ShareThis',
'meta' => array(
'proj_url' => 'http://sharethis.com',
'proj_wp_url' => 'http://wordpress.org/plugins/share-this/',
),
'groups' => array(
'deprecated',
),
),
// lots more here - you get the idea
);
foreach ($terms as $slug => $data) {
$term = wp_insert_term($data['label'], 'projects', array(
'slug' => $slug
));
$post = cftpb_get_post($term['term_id'], 'projects');
// meta for project page
if (!empty($data['meta'])) {
foreach ($data['meta'] as $k => $v) {
add_post_meta($post->ID, $k, $v);
}
}
// groups for project page
if (!empty($data['groups'])) {
foreach ($data['groups'] as $slug) {
// note, this is a WP 3.6 function
wp_add_object_terms($post->ID, $slug, 'project-groups');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.