Home Forums Front-end Issues How to get values from another post


How to get values from another post

  • Hi Community Members,

    I have a small problem,

    I have a CF in posts and I want to display that fields values in another custom post type. Actually the code to get values from another post is below.

    <p><?php the_field('field_name', 123); ?></p>

    But this is not dynamic way, I have custom template for my CPT if I use that above code it display the same value in all posts.

    My question is how can I append post id dynamically, because different CPT posts have to get values from the related posts.

    Anybody have suggestions.

  • You would need to set up a relationship between the posts, for example a post object field. Then you’d get the post ID from the current post and use that post ID to get the value from the other post.

  • If you don’t mind would you provide me a example code.

  • Hey, Thanks I got the result. And we can achieve this with relationship field?

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.