ACF type changes
-
Hi !
I’m French so I apologize if my English is not perfect š
In fact, I am using your plugin for my website and I set up some type for my ACF items and your plugin is changing it.
For example, I have an ACF called Conferences with a couple of items, as usual it have a name, the author (so me !), a type and the date of publication. But in the json file, the type is no longer “Tuesday” for example but “Conferences”. I’ve searched in every endpoints possible I can’t find my type. I don’t know if it is clear but could you help me please ?
-
Bonjour @gabi971,
I’m not sure what you mean…
Which endpoint are you accessing? For example, in my test environment I use a Custom Post Type called “yks_ee_events” that I’ve renamed “Events” and I hit the endpoint http://yikes.test/wp-json/wp/v2/events.
This CPT has custom fields defined by ACF that look like this in the admin: https://imgur.com/a/4DIyY78
When I hit this endpoint, I see my fields like this: https://imgur.com/a/gGouTsG
Also, please review this ticket to see if it helps at all: https://ww.wp.xz.cn/support/topic/acf-meta-callback-null/.
Hope that helps.
Cheers,
Kevin.P.S. Congratulations on the World Cup š
Hmmmm how can I put this…
I use a Custom Post Type call “Conferences” that I can reach with the endpoint …/conference.
But I’d like to know if it is possible to reach something which is not in the field like the field type right here : https://imgur.com/nmVQ8Ce.
Thanks for your quick answer.P.S Thank you š
Can you show me how you have set up your fields on our plugin’s page?
A screenshot like this: https://imgur.com/M3VA7m3
Feel free to obfuscate certain items if you feel the data is sensitive.
It looks like this https://imgur.com/LE2YHal
That’s all I have.-
This reply was modified 7 years, 10 months ago by
gabi971.
So you’re trying to add fields(?) from the post Human Increased to the Conference Endpoint?
What type of post is Human Increased supposed to be? Is it supposed to be a Conference Post?
Yes it is a Conference Post and all the information like the date or the author are present on the json page. I also have the field “type” but it’s no longer “Tuesday October 16th”, it’s “conference”.
I don’t understand whyIs “Type” a custom field?
I think that the reason your admin area is showing “Type” as “Tuesday October 16th” is because you’re using some type of filter that is displaying the data differently. The post type is still stored as “Conference” in the database but there must be custom code that is displaying a different field (e.g. Tuesday) for the “Type” column.
Another possible explanation is that whatever you defined as “Type” is being overwritten by WordPress’ Post Type.
Can you try renaming your “Type” field? Or perhaps creating a new field that stores the Type column?
Does that make sense?
Yeah that makes sense. I think I should create a new field for the Type column. That’s too bad, I’m just an intern I’ll have to ask ahaha.
I’ll try this tomorrow and tell you it it’s okay !Okay!
It’s also worth noting that I don’t see the Type field in the list of custom fields our plugin gathered (your screenshot – https://imgur.com/LE2YHal).
So I don’t know where this Type field is coming from. If it’s a custom field, it should show in that list. (And you should be able to rename it so it doesn’t conflict with WordPress’ standard Type field).
Let me know what you find out tomorrow!
Cheers,
Kevin.Hello it’s me again ! Before I try anything useless, I find out what I was looking for.
It’s called taxonomies, some kind of keywords ? Do you know if there is a way to get them ? It’s not at the /wp/v2/taxonomies endpointsHello! Welcome Back!
Taxonomies are not controllable by our plugin and I don’t think they’re easily accessible (by default) through the REST API. This means you’ll need to add custom code in order to add taxonomies to your endpoints.
Here is a simple class that shows how to add all of the terms for a certain taxonomy (
'taxonomy_name') to a CPT’s (cpt_slug) endpoint./** * Add taxonomies to the REST API */ class Customize_REST_API { public function __construct() { // Add taxonomies to our REST API add_action( 'rest_api_init', array( $this, 'add_taxonomies_to_rest_api' ) ); } public function add_taxonomies_to_rest_api() { register_rest_field( 'CPT_SLUG', // CPT slug 'KEY', // this needs to match meta key - this is what will show up as the key in the REST API array( 'get_callback' => array( $this, 'get_taxonomy' ), 'update_callback' => null, 'schema' => null, ) ); } public function get_taxonomy( $object, $field_name, $request ) { // $object['id'] is your CPT's post ID // 'TAXONOMY_SLUG' should be the slug of your taxonomy return wp_get_post_terms( $object['id'], 'TAXONOMY_SLUG' ); } } new Customize_REST_API();Cheers,
Kevin.Thanks ! Am I supposed to create a file with this code ? Or just add it somewhere specifically ?
Well, I don’t know how your site is setup but the easiest way to do it would be to create a file from this code and then require it in your
functions.phpfile. The best thing to do would be to add it to your site’s child theme if you’re using one. Alternatively, you could create an MU plugin out of it.I think I already saw that code somewhere… and they were talking about the functions.php file too ! But when I looked for it, I found multiple files with the same name…
One in wp-include and one in my theme folder… so if I understand well the best thing to do would be to add it in the functions.php file of my site’s theme folder ? Is that it ?Yes – the functions.php file in your theme. It’s not the best way to add it but it will work.
-
This reply was modified 7 years, 10 months ago by
The topic ‘ACF type changes’ is closed to new replies.