Git Product home page Git Product logo

Comments (5)

airesvsg avatar airesvsg commented on July 24, 2024

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.

AndreaGelmini avatar AndreaGelmini commented on July 24, 2024

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.

airesvsg avatar airesvsg commented on July 24, 2024

Hello,
please try test this theme: acf-to-rest-api-example.zip

Thanks

from acf-to-rest-api-example.

AndreaGelmini avatar AndreaGelmini commented on July 24, 2024

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.

airesvsg avatar airesvsg commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.