June 3, 201313 yr So I'm trying to create a "team" page template that features several types of information: a series a match reports (filtered by the team name- the match reports are custom post types with various post meta) future matches also filtered by team name (planning on using Simple event attendance plugin) team logo and header image users filtered by team name (user custom taxonomy) My question is what is the best way to associate the team custom post type with the user meta data of the same name? For example I have a team named Hispania. I want the players from that team to display on the Hispania team page. I am able to create the team page and the user taxonomy page separately but can't seem to associate the two. As it stands, were another team to be created it would have to be added as both a team post type and a user team which I realise is not ideal. Do any of you Wordpress gurus have any suggestions?
June 3, 201313 yr I'm not a WP guru. I think the header image could be managed by a simple IF statement in php. Creating separate post templates for eas team doesn't sound efficient. Rather a custom property of the post could be used that is defaulted from the user data and not changeable by the mortal user. I mean a similar way like the multilingual plugins tag posts by language. This would leave you with just one post template.
June 3, 201313 yr Author I'm not entirely sure I understand I'm afraid my brain is a bit muddled from reading too many articles. I am currently exploring two avenues. I have a taxonomy-team.php page from which I can query users with a single team name and have a list of team members and a single-team-page.php which displays other information related to the team but not the user. It sounds like you are suggesting a custom select box in which one would choose the users from the list of users? The problem is that it would be a very long list. Edited June 3, 201313 yr by mantis
June 3, 201313 yr I'm trying to trigger some ideas, as I'm a software designer, but know very little of coding. My starting point is always: do as little changes to standards as possible. So I would add a field in the post characteristics but not as a select box, rather as a custom field. This custom field should be display only so the user can't change it. It should be filled from the user's data by a php code.
June 3, 201313 yr Author The problem with custom fields is that there are so many possible errors when writing something and I need to make an association so the string or id number has to be exactly the same. I have made a bit of progress though, I need tm_name (meta_key) == post_title I was thinking of using get_posts() but haven't worked out the particulars yet. Cheers for your suggestions.
June 4, 201313 yr Author I think I've come up with something but unfortunately it doesn't quite work. I would love it if someone could tell me if I'm on the right track. <?php $pagename = get_the_title(); $player = get_users($args); $args = array( 'meta_key' => 'tm-name', 'meta_value' => $pagename, 'meta_compare' => '' ); foreach ($player as $user) { echo '<li>' . $user->display_name . '</li>'; } ?> The default value for meta_compare is =
June 4, 201313 yr Author Got it! I'll post it in case anyone else has the same type of question: $pagename = get_the_title(); $user_query= new WP_User_Query( array( 'meta_key' => 'tm-name', 'meta_value' => $pagename ) ); // User Loop if ( ! empty( $user_query->results ) ) { foreach ( $user_query->results as $user ) { echo '<p>' . $user->display_name . '</p>'; } } else { echo 'No users found.'; } ?> I've actually decided to do it differently but happy to have solved this particular problem.
Create an account or sign in to comment