-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ACF key in Taxonomy #43
Comments
Hi @CesarDenis, |
Hi @CesarDenis, |
Hi @airesvsg yes, I'm using. my function.php: // 1. customize ACF path
function acf_settings_path( $path ) {
$path = get_stylesheet_directory() . '/lib/acf-pro/';
return $path;
}
add_filter('acf/settings/path', 'acf_settings_path');
// 2. customize ACF dir
function acf_settings_dir( $dir ) {
$dir = get_stylesheet_directory_uri() . '/lib/acf-pro/';
return $dir;
}
add_filter('acf/settings/dir', 'acf_settings_dir');
// 3. Hide ACF field group menu item
if (WP_ENV !== 'development') {
add_filter('acf/settings/show_admin', '__return_false');
}
// 4. Include ACF
include_once( get_stylesheet_directory() . '/lib/acf-pro/acf.php' );
// 5. Init ACF to rest API
add_action( 'rest_api_init', array( 'ACF_To_REST_API', 'init' ), 5 ); |
@airesvsg You can help me? |
Yes, I'll fix this bug today. |
Oh, tks 😄 |
Hi @CesarDenis, function rest_prepare_customer( $response, $object ) {
if ( $object instanceof WP_Term ) {
$response->data['acf'] = get_fields( $object->taxonomy . '_' . $object->term_id );
}
return $response;
}
add_filter( 'rest_prepare_customer', 'rest_prepare_customer', 10, 2 ); Thanks |
Tks @airesvsg. Its work. 😄 |
Hi @airesvsg. Thanks for the great plugin. I had a similar issue where I can not see the acf data in the basic WP endpoint for a custom taxonomy. I tried the fix above and it does not work. I thought perhaps the rest_prepare_customer was only applicable to @CesarDenis's needs, and tried several other functions to filter into like rest_prepare_ with no luck. Any suggestions? Thanks! |
Hi @akhanukov, Thanks |
Via my functions.php file from within a child theme: add_action( 'init', 'akd_response_type_taxonomy', 30 );
function akd_response_type_taxonomy() {
$labels = array(
'name' => _x( 'Response Types', 'taxonomy general name' ),
'singular_name' => _x( 'Response Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Response Types' ),
'all_items' => __( 'All Response Types' ),
'parent_item' => __( 'Parent Response Type' ),
'parent_item_colon' => __( 'Parent Response Type:' ),
'edit_item' => __( 'Edit Response Type' ),
'update_item' => __( 'Update Response Type' ),
'add_new_item' => __( 'Add New Response Type' ),
'new_item_name' => __( 'New Response Type Name' ),
'menu_name' => __( 'Response Types' ),
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'response_type' ),
'show_in_rest' => true,
'rest_base' => 'response_types',
'rest_controller_class' => 'WP_REST_Terms_Controller',
);
register_taxonomy( 'response_type', array( 'message' ), $args );
} |
Sorry, still figuring out the Markdown syntax. :) |
@akhanukov I tested here and it's works. What is your url? |
This appears to do it for me using the build-in tags: function rest_prepare_post_tag( $response, $object ) {
if ( $object instanceof WP_Term ) {
$response->data['acf'] = get_fields( $object->taxonomy . '_' . $object->term_id );
}
return $response;
}
add_filter( 'rest_prepare_post_tag', 'rest_prepare_post_tag', 10, 2 ); |
I had the same problem but figured out that the value used for
|
Yikes! I just accidentally found this post searching for more clues on my other issue. Sorry for not responding to your last question @airesvsg. Not sure how I missed it. And thank you @bradmsmith and @metinucar for the solutions! I'm going to try these now. I've been using a workaround for the time being successfully, but this is the right way to do it. |
Hi there. If I do a get - I get this data - {"acf":{"pws_cityid":99}} If I'm trying to post it back - like updating it - I write- {"acf_fields":{"pws_cityid": 99}} But get this repsonse - {"code":"cant_update_item","message":"Cannot update item","data":{"status":500}} I wrote this code in function.php function rest_prepare_street( $response, $object ) {
if ( $object instanceof WP_Term ) {
$response->data['acf'] = get_fields( $object->taxonomy . '_' . $object->term_id );
}
return $response;
}
add_filter( 'rest_prepare_street', 'rest_prepare_street', 10, 2 ); and this is the code I used for registering the custom taxonomy ( which is inside projects custom post type - function street_taxonomy() {
$labels = array(
'name' => _x( 'רחובות', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'רחוב', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'רחובות', 'text_domain' ),
'all_items' => __( 'כל הרחובות', 'text_domain' ),
'parent_item' => __( 'הורה', 'text_domain' ),
'parent_item_colon' => __( 'הורה:', 'text_domain' ),
'new_item_name' => __( 'הוסף רחוב', 'text_domain' ),
'add_new_item' => __( 'הוסף רחוב חדש', 'text_domain' ),
'edit_item' => __( 'ערוך רחוב', 'text_domain' ),
'update_item' => __( 'עדכן רחוב', 'text_domain' ),
'view_item' => __( 'צפה ברחוב', 'text_domain' ),
'separate_items_with_commas' => __( 'הפרד בין רחובות בפסיק', 'text_domain' ),
'add_or_remove_items' => __( 'הוסף או הסר רחוב', 'text_domain' ),
'choose_from_most_used' => __( 'בחר מתוך הרחובות הנפוצים', 'text_domain' ),
'popular_items' => __( 'רחובות נפוצים', 'text_domain' ),
'search_items' => __( 'חפש רחוב', 'text_domain' ),
'not_found' => __( 'לא נמצא', 'text_domain' ),
'no_terms' => __( 'אין רחובות', 'text_domain' ),
'items_list' => __( 'רשימת רחובות', 'text_domain' ),
'items_list_navigation' => __( 'ניווט ברחובות', 'text_domain' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => false,
'show_in_rest' => true,
'rest_base' => 'street',
'rest_controller_class' => 'WP_REST_Terms_Controller',
);
register_taxonomy( 'street', array( 'projects' ), $args );
}
add_action( 'init', 'street_taxonomy', 0 ); Why do I get this response? |
Hi @oneguy9, |
Thanks! {
"code": "cant_update_item",
"message": "Cannot update item",
"data": {
"status": 500
}
} I have no idea how to solve this issue - |
I am able to post acf fields, but the only thing I cannot do is post an acf inside a taxonomy. I'm trying here for 3 days to write all the code i can find on the net with no success and my project is dependent on it. |
Hi @CesarDenis, |
Hi @airesvsg This is the custom field I'm trying to update - Thanks!!! |
Hi @oneguy9, |
@airesvsg /wp-json/acf/v3/term/{taxonomy}/{id} Both ended up in a blank page.... Thanks for your kind help |
@oneguy9 I changed the endpoint in the v3, now you have to access this way: More details: Thanks |
This URL returns a blank page And I have this in function.php
|
@oneguy9 please regenerate your permalinks or activate the plugin ACF to REST API. |
Yeah - I think I installed it incorrectly - I will do now some more tests and return to you with results! |
ok - now the url is working but still I get the same result {"code":"cant_update_item","message":"Cannot update item","data":{"status":500}} I think I need to write something in function.php for it to work? Thanks again and sorry for all the trouble... |
Yeah I've been there... |
@oneguy9 all fields are editable. |
I wish I was smarter :( |
@oneguy9 please send me an email with your doubts, this way we will not lose the focus of this issue. |
Hi @airesvsg, |
@airesvsg when I request the URL for my custom term:
does not come to acf key in json.
and when I request the URL your endpoints:
the acf key appears.
Can you help me?
Tks.
The text was updated successfully, but these errors were encountered: