0
  • I have user field such as "gender and country" on register form (Created with ACF).
  • Also I have post (wp default posts and CPT) taxonomies called "gender and country
  • My member can create unlimited posts and others can filter posts by taxonomy gender and country.

My question is: For each post when publish author, gender and country taxonomy value will get from user field value of gender and country. So, my member never again select gender and country. What kind code i should add function.php?

If we can this, when site admin change any user field such as gender value from male to female, all posts taxonomy will change for that author's post. Hope my question is clear with y bad english.

Best Regards

1
  • if the gender (respectively the country) is defined in the user properties, you don't need a taxonomy for that. if you have a post, you search the author and then you have the information "gender".
    – Kaperto
    Nov 11 '19 at 19:13
0

I'd suggest editing your single template, instead of functions.php. So, in a child theme, edit single.php and whatever other templates your theme uses for the CPTs, at the location where it outputs the author's name.

Where the author's name is being displayed, you can then also grab their user meta (gender and country) and output it. That way, you don't need to add any data to individual posts or CPTs, it's just attached to the user, and whenever any user data changes, it will refresh wherever it's being displayed.

It really depends on your theme what files you'll want to touch. In Twenty Sixteen, for example, the file /template-parts/biography.php is the one that shows the author's name and a touch of postmeta. It wouldn't be hard to add the gender and country to that, which would then affect anyplace that shows the author.

3
  • Thank you so much your reply. If i do this, can i filter all posts by gender and country (or/and age, membershiplevels etc) ? So on register form, user will give this information and all this information will same for that user when create a post. So others will filter posts by age, gender etc... Hope its clear my bad english.
    – ineedyou
    Nov 12 '19 at 12:39
  • Because i am using "post taxonomy filter"
    – ineedyou
    Nov 12 '19 at 12:41
  • You could make it work, with some extra steps. The problem is, you shouldn't ever query by meta. By saving the extra data (i.e. gender) as user meta, you're setting yourself up for issues. It would be better if you actually saved the extra data in a taxonomy. Then, you could query posts with something like "all posts where post type is Post, post status is Publish, and author's Gender taxonomy is Female" - which might require a custom query, but it would at least be better than querying by user meta.
    – WebElaine
    Nov 12 '19 at 16:39

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.