0

I am a drupal developer who is trying help out a friend with this task. I have a custom team post that has all the team members of the company and they sometimes post an article about their cases. If the user creates a post it gets a link of:

enter image description here

and I want to direct user to the post page that is going to direct to a page dynamically and display the posts that this team member has.

I tried to do this with pre_get_posts but unfortunately no luck.

Afterwards I thought I could apply drupal's taxonomy logic on this and i created taxonomy name "Author-Team" and I can tag authors to individual posts. This is how i created the taxonomy:

 add_action( 'init', 'build_taxonomies', 0 );
 function build_taxonomies() {
   register_taxonomy(  'author-team', 'post',   //Let WordPress know that the artist taxonomy has posts
   array(
    'hierarchical' => false,
    'label' => 'Author-Team', // This tells WordPress how to label the various user interface outlets for the artist taxonomy
    'query_var' => true,
    'rewrite' => array( 'slug' => 'author-team', 'with_front' => false))
   );
}

Then I created taxonomy template name taxonomy-author-team.php and created a dummy post and tagged it via author name 'tom', and when i go to the url of:

   example.com/taxonomies/?author-team=tom

it shows page not found(For your information taxonomy-author-team.php has only "hello world" in the template). I know I am making a logical mistake somewhere but i just couldnt figure it out even though I spend hours on it. Can anyone who accomplished this already point me what I am doing wrong or give me a better structural approach for this?

  • If the team members really are WordPress "users" you can use the default Author.php template / functions. Use the get_author_posts_url() function to link to to the page where that user's posts will all be displayed: codex.wordpress.org/Function_Reference/get_author_posts_url – Michelle Nov 29 '16 at 19:09
  • Thanks for the quick response @Michelle. Unfortunately team members are custom post type not WP "users". – Mr.T Nov 29 '16 at 19:16
  • NP, glad you got the right response below. And yes, it will be the taxonomy-author-team.php template you need to edit. – Michelle Nov 29 '16 at 19:54
2

After setting a taxonomy/post_type you firstly need to flush the rewrite rules. To achieve this you could either run $ wp rewrite flush if you have installed the wp-cli or go to "Settings->Permalinks" and save once. To list a taxonomy in the frontend the url would be example.com/author-team/tom. You could also access the taxonomy url via backend "Post->Author-Team" and then hover over a taxonomy. In the quick menu will be a link "view".

  • Ok it looks like /author-team/tom is working, but I am not sure what template i should modify to see the results. Is it going to be taxonomy-author-team.php? Thank you very much for the quick response btw. – Mr.T Nov 29 '16 at 19:48
  • 2
    Here you can see the template structure (full reference). If a variable template exists this one will be displayed. If you are using the link example.com/author-team/tom the taxonomy archive is called. So taxonomy-author-team.php should work. If you want to be more precise you could also create taxonomy-author-team-tom.php. The files have to be placed in the root of the theme wp-content/themes/yourtheme. – Fabian Marz Nov 29 '16 at 20:03

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.