Support

Account

Forum Replies Created

  • Hey David,

    Thanks for sharing your solution on the repeating field issue. I should have looked at priority more. Cheers.

  • If you know how to parse values from a WordPress database object you can query the options page. I have a repeating field called slides on a options page. It has three subfields slide_image, slide_caption, slide_link. I got the array length by using this code.

    $my_count = $wpdb->get_results($wpdb->prepare("SELECT 'option_value' FROM '$wpdb->options' WHERE 'option_name' = 'options_slides' "));

    In my case this returned:

    [0] => stdClass Object ( [option_value] => 6 )

    next to get the all the subfields I used this query:

    $my_rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM '$wpdb->options' WHERE 'option_name' REGEXP '^(options_slides)' "));

    which returns (partial example)

    [0] => stdClass Object
            (
                [option_id] => 35462
                [option_name] => options_slides_0_slide_image
                [option_value] => 13282
                [autoload] => yes
            )
    
        [1] => stdClass Object
            (
                [option_id] => 35464
                [option_name] => options_slides_0_slide_caption
                [option_value] => <h2>My Caption Title</h2>
    Discover Portland's best restaurants, bars, cafes and bakeries
                [autoload] => yes
            )
    
        [2] => stdClass Object
            (
                [option_id] => 35466
                [option_name] => options_slides_0_slide_link
                [option_value] => http://mywebsite.com/placecategory/food-drink/
                [autoload] => yes
            )

    options_slides_0_slide_image is from the options page. options_slides_0_slide_image is your repeating field name. options_slides_0_slide_image is the number of the element in the array. options_slides_0_slide_image is the name of the subfield in the repeater. Since I have 6 repeating fields the last image slide is options_slides_5_slide_image. This is my be very geeky, but maybe it will help. These comments are only related to version 5.x. For MySQL queries us a prime character ` not a single quote .

  • This is an update to my prior post. This issue is not with ACF but its the theme. I created clean test install of Twenty Fifteen, added ACF Pro, added my code from my current project. ACF worked without issue. I don’t know if this helps anyone, but it’s one less place to look for answers.

  • ACF Pro 5.3.3.1

    I’m doing a new build and I’m having the same issue. The repeater field is returning the number of items in the array and not the array.

    while( have_rows('repeater_field_name','option') ): the_row();
    // do stuff
    endwhile;

    This test fails – actual field name is different.

    It’s possible this is a conflict with the theme I’m using for this project. GeoPlaces from Templatic. Their code does not always place nicely.

  • This is how i was able to change the uploads directory for a specific ACF field. I have left some extra code for debugging.

    1 . acf/upload_prefilter/name=my_acf_upload_fieldname’ change my_acf_upload_fieldname to the name of your ACF field.
    2. $mydir = ‘/newdirectory’; // this currently writes to /uploads/newdirectory change newdirectory to your directory name.
    3. my_acf_upload_prefilter is called before the uploading of a file (whatever you name your ACF file field). Then it calls add_filter(‘upload_dir‘, ‘my_upload_directory’); which changes the directory for the upload of that file. but otherwise files upload to whatever is your default wp directory.

    function my_acf_upload_prefilter( $errors, $file, $field ) {
        
        // only allow admin
        if( !current_user_can('manage_options') ) {
            
            // this returns value to the wp uploader UI
            // if you remove the ! you can see the returned values
            $errors[] = 'test prefilter';
            $errors[] = print_r($_FILES,true);
            $errors[] = $_FILES['async-upload']['name'] ;
            
        }
        //this filter changes directory just for item being uploaded
        add_filter('upload_dir', 'my_upload_directory');
        
        // return
        return $errors;
        
    }
    add_filter('acf/upload_prefilter/name=my_acf_upload_fieldname', 'my_acf_upload_prefilter');
    
    function my_upload_directory( $param ){
        $mydir = '/newdirectory';
    
        $param['path'] = $param['basedir'] . $mydir;
        $param['url'] = $param['baseurl'] . $mydir;
    
    	// if you need a different location you can try one of these values
    /*	
        error_log("path={$param['path']}");  
        error_log("url={$param['url']}");
        error_log("subdir={$param['subdir']}");
        error_log("basedir={$param['basedir']}");
        error_log("baseurl={$param['baseurl']}");
        error_log("error={$param['error']}"); 
    */
    
        return $param;
    }
Viewing 5 posts - 1 through 5 (of 5 total)