Comments (5)
Hi @AndrGelmini,
Follow below code.
In your acf date picker fields edit the display and return format to: d/m/Y
functions.php
function date_fmt( $date, $format = 'Ymd' ) {
if ( is_string( $date ) && $date ) {
$date = str_replace( '/', '-', $date );
$date = strtotime( $date );
$date = date( $format, $date );
}
return $date;
}
add_filter( 'acf/rest_api/post/prepare_item', function( $item ) {
if ( $item && isset( $item['data']['my_repeater'] ) && ! empty( $item['data']['my_repeater'] ) ) {
foreach( $item['data']['my_repeater'] as &$v ) {
$v['d_nascita'] = date_fmt( $v['d_nascita'] );
}
}
return $item;
} );
my_repeater is the name of your repeater field.
Thanks
from acf-to-rest-api-example.
Hello and thanks..
I'm doing some tests with the script you have provided me .
I think I found the problem , When you tell me to set both the display and return to the format : d / m / Y
As I go to set and then save , the Reloading the page settings are back to those basic .. 05/05/2016 I think it's a lack of acf or is it just my thing ? you work?
if there is a solution , I would consider to take it forward , otherwise today while I was testing , I agree that this probbelma me only makes with date before today . for the later dates given me save him . to which I have modified the date- picker in the text field , and I created a mask insirimento 99/99/9999
from acf-to-rest-api-example.
Hello,
please try test this theme: acf-to-rest-api-example.zip
Thanks
from acf-to-rest-api-example.
mmm not. It does not work even with Your theme.
I think it is a incopatibilità the few plugins . but at the moment they are all necessary . What I have seen only three and one of them is acf .
I think you can quit as " solved "
unless you want to do some other tests .
from acf-to-rest-api-example.
Hi @AndrGelmini,
my example works, look: date-picker.mov
Please, insert in your functions.php the code below:
add_filter( 'acf/rest_api/post/prepare_item', function( $item, $request ) {
if ( $item && ! empty( $item['data'] ) && method_exists( $request, 'get_param' ) ) {
$id = $request->get_param('id');
if ( $id ) {
$f_r1a = get_field_object( 'field_xxxxx', $id );
if ( $f_r1a && ! empty( $item['data'][$f_r1a['name']] ) ) {
foreach ( $item['data'][$f_r1a['name']] as &$f ) {
if ( array_key_exists( 'd_nascita', $f ) ) {
$f['d_nascita'] = date_fmt( $f['d_nascita'] );
}
}
}
}
}
return $item;
}, 10, 2 );
Thanks
from acf-to-rest-api-example.
Related Issues (14)
- Can't update user custom field HOT 20
- Add more data without deleting old one HOT 8
- Can't add new repeater field
- Solution: display in RTL
- Missing example with POST/CREATE new cpt
- Help With Post Data HOT 3
- Why not use the acf front end form?
- acf is false when data is imported into wordpress
- Leading underscore at _checked-function? HOT 3
- No issues but this really is an exciting chapter in WP and decoupling.... Such respect for this source and what it enables. Thanks again! HOT 1
- PUT request not working using Oauth2 and acf Pro HOT 14
- Theme options is now in all post types pages.
- Returning "cant_update_item" error when editing Media field HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acf-to-rest-api-example.