简体   繁体   中英

How to Store Permalink to Post Authored by User in His Meta Data - WordPress

Here is the situation.

I have a custom post type, let's call it "Listings." I have numerous authors, each of whom has exactly one post of type "Listings." No more, no less.

I want a custom field, let's call it "listing_link", where the link to each author's "Listings" post is stored. I would like this to be generated automatically.

So essentially I need some kind of function that will:

1. Cycle through each author

2. Find all posts of type "Listings" by that author

3. Get the permalink to the first (and only) post of that type by that author

4. Finally save that link in a custom field I've created

I could code bits of this, but I'm really not sure where to start. When/how would this function run? How would it refresh? How do you actually save it to their meta data?

Any help would be appreciated, even if it's not a full script. I really just need to be sent in the right direction! If I can come up with a functioning solution, I will share it with the community!

Do you have to store 'listing-link'? Why not just query "listings" when you need the information?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM