Home › Forums › General Issues › Code Field / Return value of another custom field in post edit
Hi,
I would like to display the value from a custom field of another post (an option pages, actually) in my custom post type edit page.
The corresponding value would be displayed in a repeater field, and would be dynamic (it would depend on the value entered in the first column).
The value returned doesn’t even have to be edited, so it should be simply about displaying “get_field”, but I don’t know how to do that for the back end?
I tried creating a “message” custom field and add the corresponding code, but the message field doesn’t work with php (nor shortcodes).
There is this plugin to add code but it looks abandoned (i don’t even know if it works) : https://wordpress.org/plugins/advanced-custom-fields-code-area-field/
How could I solve this ? Thank you !
Even a field that allows code to be entered will not run that code. It is something you need to build. To run PHP code that is stored in a field you would need to use PHP eval() https://www.php.net/manual/en/function.eval.php to run the code in the script. This would need to be done using an acf/format_value filter. https://www.advancedcustomfields.com/resources/acf-format_value/. This is considered unsafe.
To alter a message field to show a value from another page you could create an acf/prepare_field filter for the message field and you can get the value and alter the message.
Hi John,
Thanks a lot for your answer.
Somehow I’m a little surprised (maybe because I’m kind of a noob and don’t understand the system behing custom fields) that there is no built-in or relatively easy solution to display custom fields values in the backend.
What actually surprises me is that more people don’t need this functionality (I had googled a lot before posting).
Anyway, I really thought I could build a great system with ACF alone but I’m starting to wonder if want I want to do is out of ACF scope. If you don’t answer that’s fine 😉
In short:
– I have a “product” custom post type with custom fields, including many internal ones.
– I have a “proposals” custom post type with a repeater field to add products.
=> I want, when a product is added in my Proposal post, to display info related to that product on the backend :
Example, if I add “Hotel XYZ” in the proposal:
– It would add some internal warning message related to Hotel XYZ below the table. Can be read-only, no problem.
– It would also add the Hotel XYZ description (as a field in another repeater field, I suppose). However, I want this description to be editable (so, display the product description as default value of the field).
I played around with the Clone and Relationship features but couldn’t reach the results i wanted…
Hi John,
Thanks a lot for your answer.
Somehow I’m a little surprised that it is so easy to display ACF values anywhere in the front-end, yet not so easy to display them in the backend (well, I’m kind of a noob and don’t understand the system behing custom fields, so that may be why I find it surprising).
What actually surprises me is that more people don’t need this functionality (I had googled a lot before posting).
Anyway, I’m starting to wonder if I can reach my goal with ACF alone. I’ll tell you but it’s long so if you don’t answer that’s fine 😉
In short:
– I have a “product” custom post type with custom fields, including many internal ones.
– I have a “proposals” custom post type with a repeater field to add products.
=> I want, when a product is added in my Proposal post, to display info related to that product on the backend.
Example, if I add “Hotel XYZ” in the proposal:
– It would add some internal warning message related to Hotel XYZ below the table. Can be read-only, no problem.
– It would also add the Hotel XYZ description (as a field in another repeater field, I suppose). However, I want this description to be editable (so, display the product description as default value of the field).
I played around with the Clone and Relationship features but couldn’t reach the results i wanted…
ACF is a plugin built primarily for developers. Think of it as a shell that lets you do things in the WP admin that you can do without ACF, but without the need to code those changes. The most time consuming part of adding custom a custom field UI to a post page is the coding required to do so. The primary focus of ACF is to make that part of building a custom site less painful so that you can get on with the important part of building the custom front end by using simple functions.
This is one >90% of it’s users do with it.
ACF provides a host of filters and actions that can be used to extend this functionality for those that want to do more. It is entirely possible that you can do what you want, but there is nothing built in that will allow you to do it. Granted, it sometimes takes knowing the plugin well and understanding what can be done with various fields to come up with a solution.
There are other tools that will let you incorporate ACF fields because they have added extensions that can deal with the data that ACF stores. But these will always be inferior to doing the actual coding yourself do to the complex nature of some of the field types in ACF.
Hi John,
Thank you.
I understand what you’re saying, and I wasn’t really expecting it to be built in. You answered my main question: it is actually possible to do what I want (as in: there is no technical limitation somehow)
In this case I will ask help to a real developer, probably via codeable.io.
Thank you!
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.