0

Hi & thanks in advance to those who could help me sot out he below:

  • I have customized my home page, using tpl-home.php to show the authors (eg users...) of the most recent posts - nothing specific yet...-.
  • I have customs fields (using ACF) and customs taxonomies, among which the 'member' taxonomy. Some members can be post authors (eg. defined users...) , and I want to create a link from the post author to the corresponding member page (eg. sing-member.php) page. Of course , I defined a custom field within ACF with the post_author ID value, which takes the author/ user_id. In short: I have a custom field 'member_author' with the user_id, pull the post_author value from the list of most recent posts and want to link that to the single-member.php to show the details for the said author if & when he also is amember here are link to my modified home page and to the single-member.php page for the related $post->author / member_author ID

Many thanks again for those patient enough to put me on the right track! Regards, JMB

2 Answers 2

1

From reading your question, I assume the following things.

  • Your post(s) are related to an author (user)
  • Your post(s) are related to a term in the Custom Taxonomy "members", which would have the same slug as a users nicename/username/something.

First, may I recommend losing the 'Members' taxonomy, as Users already have author pages which can be customized author.php. You can create a secondary WP_Query here and list any posts you want attached to that author.

If you want to relate the two together, you'll have to get the post author, then do a compare of the term label/slug to some item on the user. Something like:

$term = get_term_by( 'name', $post_author->first_name . ' ' . $post_author->last_name, 'Members' );
$term_link = get_term_link( $term->term_id ); // mysite.com/members/john-doe

One other thing to note is the template for a single term in Members would be taxonomy-members.php for a general term template, or taxonomy-term-john-doe.php for a specific term.

4
  • Thanks Eric,I'll try out your $ter query, as for 'losing' the Member taxonomy, I'thought of using the user with custom fields, but the thing is my 'Members can either be article authors or NOT, and not the 'other way round... (hence the custom fied 'member_author' created using ACF, which -so fais the link to the $post-author (ID)'
    – JMB
    Nov 24, 2013 at 16:07
  • I'll try out your $term query, as for 'losing' the Member taxonomy, I'thought of using the user with custom fields, but the thing is my 'Members' can either be article authors or NOT, and not the 'other way round... (hence the custom fied 'member_author' created using ACF, which -so far - the link to the $post-author (ID)'. I guess I could use the slugs instead - and therefore loose the 'memeber-author' custom field, which would have become redundant / useless ? - My custom post type is 'member' w/o 'S', so I guess my archive file syntax is right, if not completely consistent w/WP?
    – JMB
    Nov 24, 2013 at 16:15
  • I've just tried what you suggested, but strangely, neither $post_author->xxx values are defined or rather output blank, so I tried the following (Note: my custom post-type is'member', and my taxo is 'member_type'): $term = get_term_by( 'name', $author_name, 'member' ); a var_dump($term) returns boleean :false, and of course the link outputs nothing... any clue ? THank you for your time Regards, JMB
    – JMB
    Nov 24, 2013 at 18:22
  • Sorry, I thought that "Members" was a custom taxonomy, not a post type. Nov 25, 2013 at 13:58
0

Hi to all & thanks to Eric,

I have finally managed a somewhat inelegant workaround solution for this: the issue I had was in fact building the URL to link to my 'member single page... What I ended up doing is rebuilding the permalink to the said page like so:

$author_name=str_replace(' ','-',strtolower(sanitize_user(get_the_author_meta('display_name'))));

Which would give me the necessary slug to build my link :

<a href="<?php echo get_site_url();?>/membre/<?php echo $author_name; ?>"><?php echo get_the_author_meta('display_name');?></a>

Thank you for reading me !

1
  • Pretty much what I had in mind. For best practice, use <?php echo home_url( '/member/' . $author_name ); ?>. home_url is better to use, as it can be different than site_url if you have WP in a folder. Nov 25, 2013 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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