0

I have a custom post type for which I want to create either a meta box or an ACF field. The user can then specify three posts of the same post type to be featured on a page. The links have to persist between posts, what I mean by that is that if I declare post a, b, and c to be the featured articles, and I hit save, I want to be able to go to a different article and see the same three choices in the box. That way I can always be sure that there will be at most 3 articles featured on the page.

Is this possible?

  • Is this a front-end user? If so, and if the user is logged in then you can store the article IDs in their user meta. If not, you'll probably have to use a cookie to store the IDs. Or is this an admin user? In that case the featured post IDs can either go in the blog meta, or as flags on the posts, or as a separate post object that just contains these IDs, or something else - there are plenty of options. – Rup Aug 13 at 13:16
  • The featured articles would ultimately be displayed on the front-end, where the logged in status doesn't matter. I think a cookie can only be set once I have a solution that lets me persists data throughout all posts, though? How do I create a post object that saves and loads the same data on all posts? – Hewe Aug 13 at 13:18
  • Just to clarify - if you're saying that you are editing post A, and you select posts B, C, and D, then when you edit post B, C, or D, you also see those same selections - yes, you can do that. ACF calls it "bidirectional relationships" which basically link posts to each other from both directions. However, if you are talking about editing any Page and you want to see a specific set of postmeta that is more of a global setting, what you will want to do instead is to create an ACF options page where you select the 3 featured posts. That way there's only 1 place to manage them. – WebElaine Aug 13 at 15:06
  • @WebElaine To clarify: I select B, C, and D on post A. I want B, C, and D to show on ALL the other posts. I use ACF Pro and don't see a birelational option. I do see "relationship" under Field Type, but the 3 links I select on one post don't show on any of the other posts. The query i would like to run on the front-page is "show me all post names tagged as featured, but allow only 3 to be featured at a time." I just started on an ACF options page, but since you mentioned it was global I would rather have an option that was as local as possible. Can you elaborate on the bidirectional relation? – Hewe Aug 13 at 19:36
  • If you want something "global" bidirectional is definitely not what you want. It simply applies postmeta to all the associated posts. It would not provide a way for all the other (non featured) posts to show what posts are featured. An options page would give you 1 single place to set the featured posts so you could be sure only a certain max are set at any given time. – WebElaine Aug 13 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.