Support

Account

Forum Replies Created

  • Use the admin_enqueue_scripts action like this

    function load_custom_wp_admin_style() {
            wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' );
            wp_enqueue_style( 'custom_wp_admin_css' );
    }
    add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );

    More information you will find in WordPress codex https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts

  • I think it has something to do with the acf-qtranslate, because the standard ACF file field shows all files in media gallery.

  • Each layout in a flexible content is wrapped in a div with a data attribute data-layout="NAME_OF_LAYOUT".

    You can include a css file for the back-end and set your desired width for the layout like this:

    .acf-flexible-content .layout[data-layout="NAME_OF_LAYOUT"] {
        width: 500px; /* Your desired width */
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
    }
  • I think you have to use get_sub_field instead of the_sub_field

    function horairesEte() {
    	if( have_rows('horaires_ete', 'option') ):
    		while ( have_rows('horaires_ete', 'option') ) : the_row();
    			return '<span class="jours">'.get_sub_field('jours').'</span><span class="ouverture">'.get_sub_field('ouverture').'</span>-<span class="fermeture">'.get_sub_field('fermeture').'</span>';
    		endwhile; 
    	endif;
    }
    add_shortcode('horaires_ete', 'horairesEte');
  • I’m looking for a solution as well. I have a Taxonomy Field and some Clone Fields and want to show a Clone Field depending on the selected taxonomy.

    Let’s say I have the taxonomies “Books”, “Videos” and “Music”. If I select “Books” as the taxonomy I want to show the Clone fields for Books; if i select “Videos” I ant to show the Clone fields for Videos…

    My idea was to create a new conditional rule with the new ACF 5.7 possibilities but I have no idea how to create a function that would add this new conditional logic.

    Maybe someone got the idea how to do this – Thanks

  • As simple as this:

    $rows = get_field('repeater' ); // get all the rows
    $specific_row = $rows[YOUR_ROW_NUMBER]; // 0 will get the first row, remember that the count starts at 0
    $title = $specific_row['SUB_FIELD_NAME']['title];

    In your specific example the SUB_FIELD_NAME would be downloads_acf_field_single_product

  • Is there something new to it. I am also looking for the possibility to add settings to the layout within a flexible content field.

  • It doesn’t matter in which level of the repeaters the field is placed.

    Try this code to get the image sizes as options for your radio field:

    <?php
    function acf_load_image_sizes_field_choices( $field ) {
    	global $_wp_additional_image_sizes;
    
    	$field['choices'] = array();
    
    	foreach ( get_intermediate_image_sizes() as $size ) {
    		if ( in_array( $size, array('thumbnail', 'medium', 'medium_large', 'large') ) ) {
    
    			$width  = get_option( "{$size}_size_w" );
    			$height = get_option( "{$size}_size_h" );
    			$crop = (bool) get_option( "{$size}_crop" );
    
    		} elseif ( isset( $_wp_additional_image_sizes[ $size ] ) ) {
    
    			$width = $_wp_additional_image_sizes[ $size ]['width'];
    			$height = $_wp_additional_image_sizes[ $size ]['height'];
    			$crop = $_wp_additional_image_sizes[ $size ]['crop'];
    
    		}
    		
    		$image_crop = "";
    		if ( $crop == 1 ) {
    			$image_crop = " - cropped";
    		}
    
    		// set the value for field values and labels as you like
    		$value = $size;
    		$label = $size . " ({$width}x{$height}{$image_crop})";
    
    		$field['choices'][ $value ] = $label;
    	}
    
    	// add full size option
    	$field['choices'][ 'full' ] = "Full size";
    
    	return $field;
    }
    add_filter('acf/load_field/name=image_size', 'acf_load_image_sizes_field_choices');
    ?>

    This filter works for the field named image-size.

    I hope you get the idea how this works and you can adjust it to your needs.

    Regards
    Thomas

  • I tested the accordions with the new ACF v5.6.7. If you want to use the accordions within tabs, you must use a last accordion field with “Endpoint” set to Yes before you start the next tab.

    It’s a bit more complicated than with the Accordion Tab Field plugin – but has the advantage that you can also create tabs within an accordion.

    The only downer: If you have a site already using the Accordion Tab Field plugin both accordions not working. That’s because the core accordion and the plugins accordion using the same field name in code. That’s why ACF’s script and CSS for the accordion also affects the fields created by the plugin and vice versa.

    Since I use the plugin on many pages of my clients, I’ve been looking for a solution to continue to use the plugin (so I do not have to change all affected fields) and still be able to update to the new ACF version.

    Here is my approach (for ACF Pro only):

    First be save that you didn’t have set up accordion fields with the new ACF core accordion field. Otherwise, these will also be changed.

    I changed the field name in the Accordion Tab Field plugin acf-accordions-v5.php and all necessary class names in the .js and .css files to an unique name (e.g. my_accordion). The affected class names are:
    .acf-field-accordion -> .acf-field-my-accordion
    .acf-field-object-accordion -> .acf-field-object-my-accordion)

    After that the old accordion fields are broken and now you should not update the field groups.

    Now you have to go into your database and open the wp_post table (change the suffix “wp”, if you have defined your own suffix in the wp-config.php).

    I DO NOT NEED TO REMEMBER THAT WORKING ON THE DATABASE ALWAYS REQUIRES A DATABASE BACKUP FIRST

    In this table all the accordion fields are saved. To list them all query like this:
    SELECT * FROM wp_posts WHERE post_content LIKE '%"type";s:9:"accordion"%'

    To change this entries use a query like this:

    UPDATE wp_posts
    SET post_content = REPLACE(post_content, '"type";s:9:"accordion"', '"type";s:12:"my_accordion"')
    WHERE post_content LIKE '%"type";s:9:"accordion"%'

    The replacement string must contain the field name you set in the acf-accordions-v5.php and you have to set the s parameter to the length of that string. In the example query the field name my_accordion is used and therefore it must be s:12.

    Now your fields are re-linked to the Accordion Tab Field plugin fields.

    I hope this approach works for anyone who wants to use the new ACF v5.6.7 and the plugin together.

  • Hi Elliot,

    thanks for your reply and the information.

    But your fix doesn’t work at all. OK. – the fatal error is gone, but since ACF and the plugin still use the same field name, we now have a mix of both types of fields.

    The results are blank and very narrow bars that do not open the contents of the accordion.

    I think you have to rename the field name as well!

    Thanks
    Thomas

  • I’ve been using ACF since the first version and do not want to miss it anymore and Elliot is really doing a good job.

    But the new version with the Accordion feature disappoints me a little bit:

    1. The core Accordion field is called with the same class name as the plugin
    Accordion Tab Field, which has been available for a long time (4000+ active installations). The result is that after updating to the new ACF version, should the Accordion plugin be active, WordPress will stop working with a Fatal error!

    And the new Accordion field is using the same field name as the plugin.

    Even customizing the class name in the Accordion Tab Field plugin would not solve the problem, since the field name is the same. Thus, fields previously assigned to the Accordion of the plugin would now be mapped to the core accordion. The result: The fields do not work anymore!

    The plugin should also be known to Elliot and he should have taken more care here and choose a different class name / field name so that this error does not occur!

    2. That the new core Accordion does not work in tabs is incomprehensible. Even with the idea of implementing such a function, one would have to come up with the idea that this function will also be used in tabs. And the Accordion plugin shows clearly that it is possible.


    @Elliot
    Why did not you contact the developer of the Accordion plugin and talk about taking this feature into the core of ACF? That would have saved everyone a lot of trouble. Why is a new feature not tested with all other modules (especially the tabs)?

    Fact no. 1 should be solved very quickly, because the update of ACF would break all sites using the Accordion Tab Field plugin!!!

    I hope the new Accordion function is revised very quickly, so that we could work with it reasonably.

    Excuse my harsh words, but I had to get rid of that.

  • It looks like your field hero is a group field. If so try this

    <?php
    		
    // vars
    $hero = get_field('hero');	
    
    if( $hero ):
        if( $hero['image'] ): >
            <div id="hero">
                <img />" alt="<?php echo $hero['image']['alt']; >" />
            </div>
    
        <?php endif; >
    <?php endif; >
  • It seems that you loop the rows two times. If so save the last row_index in a variable and add this var to the row_index in the second loop.

    It should look like this:

    <?php
        if( have_rows('boxes') ):
        while ( have_rows('boxes') ) : the_row();
        if( get_row_layout() == 'text' ): ?>
    
            <div class="box field-class-<?php echo get_row_index(); ?>">   
                <?php the_sub_field('content'); ?>
            </div>
    
    <?php elseif( get_row_layout() == 'image' ): ?>
    
            <div class="box field-class-<?php echo get_row_index(); ?>">   
                <?php the_sub_field('content'); ?>
            </div>
    
    <?php elseif( get_row_layout() == 'photo_slider' ): ?>
    
            <div class="box field-class-<?php echo get_row_index(); ?>">   
                <?php the_sub_field('content'); ?>
            </div>
    
            <?php // on the last get_row_layout()
            $r = get_row_index(); ?>
    
    <?php endif; endwhile; else : endif; ?>
    
    <?php // start the second loop
    if( have_rows('boxes') ):
        while ( have_rows('boxes') ) : the_row();
        if( get_row_layout() == 'text' ):
            $r = $r + get_row_index(); ?>
    
            <div class="box field-class-<?php echo $r; ?>">   
                <?php the_sub_field('content'); ?>
            </div>
    
        <?php elseif( get_row_layout() == 'image' ):
            $r = $r + get_row_index(); ?>
    
            <div class="box field-class-<?php echo $r; ?>">   
                <?php the_sub_field('content'); ?>
            </div>
    
    <?php elseif( get_row_layout() == 'photo_slider' ):
            $r = $r + get_row_index(); ?>
    
            <div class="box field-class-<?php echo $r; ?>">   
                <?php the_sub_field('content'); ?>
            </div>
    
    <?php endif; endwhile; else : endif; ?>
  • I figured out what’s going wrong:

    In the ACF RGBA Color Picker the apply_filters( "acf/acfrb_color_picker/palette", true ) in set in the __construct() of the field class in the $this->settings = array(). This setting is later used in a wp_localize_script() function in the function input_admin_enqueue_scripts()

    That seems to be to early. I moved the apply_filters... directly in the localized script part and now it works.

    Maybe you get an idea why this is working if setting the fields with ACF field groups page and not working if fields created via PHP.

    Thanks again for your help!

  • John, thanks for your testing.

    I have checked my database and also checked if I have double field names (because I created the fields via PHP). No errors, no doubles.

    To be sure, I deleted all entries from the database belonging to my options page (no worries, I’m in a testing environment).

    After that, I added two new colors to my repeater and checked the database again. Everything is fine.

    But I was surprised when I tried to read and print the repeater field this way

    <?php
        $test = get_field('MY_REPEATER', 'MY_OPTIONS_PAGE');
        echo "<pre>";
        print_r($test);
        echo "</pre>";
    ?>

    I only get the number 2, the count of repeater rows.

    Then I create a repeater with fields in the backend (not via PHP) and tested this. And yes, it works!!!

    I exported this field groups to get the code and copy this into my functions.php to create the field groups via PHP to test if I make any mistakes on my first try.

    And that’s the next surprise: Now it does not work!!!

    With the above test I only get the number of the repeater rows and no array.

    So it must have to do anything with registering the field groups via PHP.

  • This code is from the Repeater Field documentation and should do what you want:

    <?php 
    
    $rows = get_field('slideshow'); // get all the rows
    $rand_row = $rows[ array_rand( $rows ) ]; // get a random row
    $rand_row_image = $rand_row['slideshow-image']; // get the sub field value 
    
    $image = wp_get_attachment_image_src( $rand_row_image, 'large' );
    // url = $image[0];
    // width = $image[1];
    // height = $image[2];
    ?>
    <img src="<?php echo $image[0]; ?>" />
  • I didn’t see what this has to do with ACF.

    And why do you want to hide these post on the admin screen. If you hide them, how to get access to them?

  • What did you get if you

    <?php
    echo "<pre>";
    print_r($hero);
    echo "</pre>";
    ?>

    BTW: There’s one index to much echoing the $hero parameters:

    <?php
    		
    // vars
    $hero = get_field('hero');	
    
    if( $hero ): ?>
    	<div id="hero">
    		<img src="<?php echo $hero['url']; ?>" alt="<?php echo $hero['alt']; ?>" />
    	</div>
    
    <?php endif; ?>
  • I think the get_row_index() function will do the work

    <?php
        if( have_rows('boxes') ):
        while ( have_rows('boxes') ) : the_row();
        if( get_row_layout() == 'text' ):
    ?>
    
    <div class="box field-class-<?php echo get_row_index(); ?>">   
        <?php the_sub_field('content'); ?>
    </div>
    
    <?php elseif( get_row_layout() == 'image' ): ?>
    
    <div class="box field-class-<?php echo get_row_index(); ?>">   
        <?php the_sub_field('content'); ?>
    </div>
    
    <?php elseif( get_row_layout() == 'photo_slider' ): ?>
    
    <div class="box field-class-<?php echo get_row_index(); ?>">   
        <?php the_sub_field('content'); ?>
    </div>
    
    <?php endif; endwhile; else : endif; ?>
    
  • I think you are wrong. According to the documentation for the acf_add_options_page() the post ID can also be any string – only the default ist 'options'.

    $args = array(
    ...
    /* (int|string) The '$post_id' to save/load data to/from. Can be set to a numeric post ID (123), or a string ('user_2'). 
    	Defaults to 'options'. Added in v5.2.7 */
    	'post_id' => 'options',
    ...
    )
    

    Since I also get the values in other situations (see the 2nd example where I get all color values for the radio field or the 3rd example where I get the value for the other field from the same options page), the code can not be so wrong.

    Since the 'post-id' was introduced in v5.2.7 I always use this.

    Sorry, but this is not the solution…

  • Thanks James – I have send this to the support team.

  • Thank you, @James

    After playing around with the priority, I found my mistake. I called the acf/render_field_settings action in a function that itself has been called in with the action acf/input/admin_enqueue_scripts.

    If I call the acf/render_field_settings action in the __construct() or if I add a function called on admin_init it works.

    Thanks for your help.

  • You can also go this way

    $rows = get_field('repeater' ); // get all the rows
    $specific_row = $rows[YOUR_ROW_NUMBER]; // 0 will get the first row, remember that the count starts at 0
    $sub_field_value = $specific_row['SUB_FIELD_NAME']; // get the sub field value

    This also explained on the tutorial page for repeaters https://www.advancedcustomfields.com/resources/repeater/

  • Thanks for your answer. But for me a repeater displaying as a row can’t be collapsed if no field for the select option is set. There’s no difference between row, table or block design.

Viewing 25 posts - 1 through 25 (of 40 total)