0

A client requires that a website he ordered uses a group-based system for navigation and administration. Eeach group effectively represents a department in a company and there will be a fairly small number of groups. First I just want to mention that the BuddyPress plugin doesn't really seem to meet all the requirements.

Requirements:

  1. Each group is assigned a group manager who can create content (posts of various types)
  2. example.com/group_name would lead to a group hub where there would be some basic info about the group, a few generic queries loading latest posts for that group and some other stuff strictly related to the group
  3. example.com/group_name/news would lead to a query page displaying latest news posts created by the group (other post types would also have their query pages)
  4. The group manager can only create posts for his group and they have to be reviewed by a head manager before being published (solvable by certain user roles)
  5. Posts should have a url structure of example.com/group_name/news/post_name
  6. They also want each group to have it's own menu and logo and subpages like example.com/group_name/about
  7. I also cannot really use wordpress multisite option, because the homepage is sort of like a global hub - i.e. something from all groups gets pulled there. Thats for example latest news across all the groups and they need to be paginated and so on. There also needs to be a page like example.com/news where you could filter out which group you are interested in etc.

First approach:

I started off by creating a custom group taxonomy:

register_taxonomy(
     'groups',
     ['post', 'user'],
     [
        'public' => 'true',
        'labels' => $labels,
        'hierarchical' => true,
        'capabilities' => [
            'manage_terms' => 'edit_users',
            'edit_terms' => 'edit_users',
            'delete_terms' => 'edit_users',
            'assign_terms' => 'edit_users',
        ]
    ]
);

Then I created some basic rewrite rules:

$groups = get_terms([
    'taxonomy' => 'groups',
    'hide_empty' => false
]);

foreach ($groups as $group) {
    add_rewrite_rule($group->slug . '/?$', 'index.php?&pagename=group&groups=' . $group->slug, 'top');
}

add_rewrite_rule('([^/]*)/news/?$', 'index.php?post_type=post&groups=$matches[1]' , 'top');
add_rewrite_rule('([^/]*)/news/([^/]*)/?$', 'index.php?groups=$matches[1]&name=$matches[2]&post_type=post' , 'top');

And setup custom link creation:

function __custom_post_link($link, $post, $leavename = true)
{
    $terms = get_the_terms($post, 'groups');
    if (!$terms) return $link;
    $term = $terms[0]->slug;
    if ($post->post_type == 'post') {
        $link = str_replace($post->post_name, $term .'/news/' . $post->post_name, $link);
    } 
    return $link;
}

add_filter('post_type_link', '__custom_post_link', 10, 3);

But here I stopped because I figured it might be better to use custom post_type instead. Because I am going to have to display some additional information on group hub pages I will probably have to store some post meta information. It also seems to me that it would be easier to use a custom post type to get around the basic routing problem with example.com/group_name. It should also be possible to set a page as a child for the custom post, right? If so that would resolve things like example.com/group_name/news.

Question: When creating a system centered around a set of groups with the requirements above, do you think it is better to use a custom taxonomy or a custom post type? Or is there an even better way?

0

I don't see why you can't multisite. On the main site you'd just need to switch_to_blog(), get content from one of the group blogs, then restore_current_blog().

| improve this answer | |
  • Yes but that's a very expensive operation from what I understand. And lets say I need to pull the latest news from across all the groups - that means I need to make n queries to db and then sort them. The problem increases even further once I need to paginate the content. I will update the question to reflect this concern. – PeterTheLobster Feb 18 '17 at 17:54
  • true, it's not cheap, but it's not that bad (WP Core's object caching helps). For example, here is a multisite that I developed for a client. The facilities shown on the map are stored as CPT's in 14 different blogs. Yes, the page doesn't load immediately, but it is not unacceptably slow. – Paul 'Sparrow Hawk' Biron Feb 18 '17 at 18:09
  • and you're right, dealing with pagination would be a complication. I don't know if it would be acceptable for your case, but I would suggest that the main site simply show the "most recent" content from each blog, and when and end-user wanted to see more, just send them to the particular page/archive in the blog in question. Also, dealing with restricting who has permission to edit what if everything is in a single site is not trivial (that's the main reason I built the site I mentioned above as a multisite). – Paul 'Sparrow Hawk' Biron Feb 18 '17 at 18:14
  • Yeah everything apart from the way the db records are disconnected fits my needs. It's just a shame that the client requested already that the homepage needs paginable latest news, a calendar of upcoming events and some other stuff. – PeterTheLobster Feb 18 '17 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.