Support

Account

Forum Replies Created

  • @hube2 first of all thanks a lot!!
    and with a little more thinking I came up with this solution😅, not sure if it’s good but at least it works! also I would be happy if you could tell me they ways to improve it more.

    function acf_json_ipm($json_acf_url_field, $acf_radio_field) {
            
            //Check if data field is set to Manual
            if (get_field($json_acf_url_field) == 'manual') {
                // Stop importing from JSON
                return;
            }
            
                //Make a request
                $json_request = wp_remote_get( $json_acf_url_field );
                if( is_wp_error( $json_request ) ) {
                    return false; // Bail early
                }
                
                // Get JSON and Decode
                $json_body = wp_remote_retrieve_body( $json_request );
                $json_data = json_decode( $json_body );
               
                // Import values from JSON
                $values = array (
                    
                    'field_1234' => $json_data->value1, 
                    'field_5678' => array (
                        'field_8901' => $json_data->value2, 
                        'field_2345' => $json_data->value3, 
                        'field_6789' => $json_data->value4 
                    ),
                    'field_0123' => $json_data->value5, 
                );
    
                //Update Group field and save1
                update_field('acf_group_field_key', $values);
                
                //Put the checkbox to manual
                update_field($acf_radio_field, 'manual');
           }
  • @hube2 Thanks for the answer!
    I’ve tried to mess around with it and I was thinking about the part that you said how and where the JSON is stored and I came up with this:

    $json_url = get_field('field_of_json_url', $post_id);
        
     $request = wp_remote_get( $json_url );
    if( is_wp_error( $request ) ) {
            return false;
        }
    
        $contents = wp_remote_retrieve_body( $request );

    but now the problem I have is where and how I have to put and run the code you gave me? I’ve tried a lot but nothing happened. I’ve event read the update_field() document over and over but couldn’t understand it. 🙁

  • @hube2 Thanks for the answer! I could understand somethings but still need to think more I guess.

    Is it possible to give a really simple example since I’m still confused how to work with update_field with field keys.

    something like this:
    getting title and body data from here and then decode it and then putting it into the “title_field” and “body_field” fields when the publish button has been clicked.

    also the answer that you said is it gonna be into a separate plugin for ACF or also can be used into theme files?

  • @flipty Well I came up with this solution that you can put JSON data into a field and then on theme file decode it and use it. (the decoded data won’t be in mysql) but I prefer to not put the JSON data directly because there would be lot of data that I won’t use it and also I prefer to put them into mysql as well.

  • Try using reset_rows(); after endwhile;

  • I think you’ll need to change some items; I’ve marked them with “CHANGE_THIS”.
    class CHANGE_THIS extends WP_Widget

    function __construct() {
        parent::__construct(
          'CHANGE_THIS', // Base ID
          __('CHANGE_THIS', 'domainname'), // Name
          array( 'description' => __( 'Email, phone, FB link', 'domainname' ), ) // Args
        );
      }
    add_action( 'widgets_init', function(){
      register_widget( 'CHANGE_THIS' );
    });
Viewing 7 posts - 1 through 7 (of 7 total)