Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • This is something that happens when saving a large number of fields. There are too many DB queries that cause the page to time out. This has been discussed here before, many times.

  • doing something like this would be more complicated than adding a field to the category. When saved the value would be saved to the category and not indicated what user is following.

    This is not something that can’t really be done with ACF. You need to record information based on the user, probably in user meta, that stores a list of categories they are following and then query based on the value stored for the current user.

    You could potentially use an ACF Taxonomy field on the user admin page and then use AJAX to store values to the current users page.

  • Old question, but if you have not solved this, the issue is that you need to supply the post ID in both the if and while statements

    
    if( have_rows('casino_data', 'option') ):
    
    while( have_rows('casino_data', 'option') ):
    
  • Found a solution:

    JS

    acf.add_filter('select2_ajax_data', function(data, args, $input, field){
      const post_type_field = acf.findFields({
        name: 'post_type',
        sibling: field,
        limit: 1,
      });
      const post_type_value = post_type_field.find($('select')).val();
    
      if (post_type_value) {
        data.post_type = post_type_value;
      }
    
      return data;
    });

    PHP

    add_filter('acf/fields/post_object/query/name=featured_posts', function($args){
        if (!empty($_POST['post_type'])) {
            $args['post_type'] = esc_attr($_POST['post_type']);
        }  
     
        return $args;
    });
  • 
    $colors = get_field( 'cor' );
    
    // Create a comma-separated list from selected values.
    if ($colors) {  
      $boxes = array();
      foreach ($colors as $color) {
        $boxes[] = '<span style="height: 20px; width: 20px; margin-right: 3px; position: relative; background-color: '.$color.';"></span>';
      }
      echo implode(', ', $boxes);
    }
    
  • You have some issues in your code, for example this

    
    if ($result = term_exists($term, $taxonomy)) {
    

    should probably be

    
    if ($result == term_exists($term, $taxonomy)) {
    

    there are several of this same type of error in the code that you’ve posted.
    This is usually why some people code like this

    
    if (term_exists($term, $taxonomy) == $result) {
    

    because the above would create an error if you use ‘=’ instead of ‘==’ rather than fail quietly.

  • This question is really about how to do this in Elementor. For this you will likely need create custom templates and or blocks. Beyond that I can’t help much with elementor and I would look for documentation and tutorials on creating templates and using ACF with those templates.

  • You would need to contact the developers for feature requests.

    Overall, the repeater field is not the best choice for creating something like products and a custom post type would be better suited for that type of thing.

  • You really can’t to this with ACF. ACF has no way to show images from a certain term.

    I would build a shortcode and skip ACF entirely by doing a query to get the images in the term.

    If you really want to do this with an ACF gallery field you could create an acf/load_value filter (priority > 10), ignore whatever value the field has do the same query and return an array of attachment IDs. Basically this makes the ACF gallery field just a placeholder. You’d probably also need to add another field to set the term to use for the gallery and get/use that value in the query.

  • acf/validate_save_post fires twice, the first is during an AJAX request to validate fields. During AJAX requests is_admin() is always true. You need to add a test for this

    
    add_action( 'init', 'blockusers_init' ); 
     function blockusers_init() { 
     	if ( is_admin() && check_role('mycustomrole') && 
                 (!defined(DOING_AJAX) || !DOING_AJAX)) { 
     		wp_redirect( home_url() ); 
     		exit; 
     		} 
    }
    
  • Thanks for clearing that up. In the meanwhile, I managed to achieve the visual result I was aiming for using the CSS column-count and column-span properties.

  • answered my own question, used the array:

    <?php 
    $link = get_field('link');
    if( $link ): 
        $link_url = $link['url'];
        $link_title = $link['title'];
        $link_target = $link['target'] ? $link['target'] : '_self';
        ?>
        <a href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>"><?php echo esc_html( $link_title ); ?></a>
    <?php endif; ?>
  • A simple solution if the goal is to keep templates clean would be to create a helper function like

    function get_image_field_src_by_size($field_name, $size){
        
        $image_id = get_field($field_name);
        $image = wp_get_attachment_image_src($image_id, $size);
        return $image[0];
    }
    
    <div style="background-image:url(<?php echo get_image_field_src_by_size('image_field_name', 'image_size_name') ?>)"></div>
    

    Or, without a function and just a bit uglier inline

    <div style="background-image:url(<?php echo wp_get_attachment_image_src(get_field('image_field_name'), 'image_size_name')[0] ?>)"></div>

  • Start here https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/

    You would have to loop over all of the layouts in the flex field to populate the select field.

    I can’t give you any help on dynamic population would work as new layouts are created, not something I’ve ever tried before. But it would involve creating a JS action that triggers when a layout is added or when the field you’re basing it on changes and then writing JS to update the select field(s) choices.

    Targeting events on ACF fields would look something like

    
    $('[data-key="field_XXXXXXX"] .acf-field select')
    
  • I accept this has a solution. After my last message, I checked a bit and the only way seemed was to actually read the JSON file stored in the plugin and get the field keys from there.

    But thanks for pointing out in the right direction with acf_get_field_groups() hint. I’m gonna check this out and probably will share my solution here if I could have one.

    Thanks a lot for the quick support!

  • 1) Yes, I first create the post and get the post ID. And then pass it down to the fields.

    2) Ah, that’s a good point. So you mean that if the fields do not exist, then we must use field key (e.g., field_1231231) instead of the field name (e.g., _products)? However, my client is how do I get the field key programmatically by providing the field name? if possible at all?

    Sorry, I confused field key with field name. Yes, field keys (e.g., field_123123) are unique throughout the site in all field groups. Only field names (e.g., _products) are being used in multiple field groups.

  • If you are using wp_insert_post() then

    1) There cannot be a post ID before it is inserted, you will only have the correct post ID after it is inserted.

    2) The fields will not exist on the newly inserted post. Even with the correct post ID the fields will not exist and ACF will fail to find the reference and fail to update the field. When adding/updating fields that do not exist you must use the field keys, see the update_field() documentation.

    Field keys, unlike field names, must be unique to your entire WP site. All field keys must be unique, they cannot be repeated in multiple field groups. If you have duplicate field keys then this is more then likely the source of your issue.

  • ACF does not directly support Polylang and this would require altering the popup used by acf to allow selecting a language.

    I don’t know of any way to accomplish what would need to be done, at least not directly.

    I don’t have any specifics but I would look into the following. Create and acf/save_post action. In this action get the language set for the post and get the selected terms. Check each of the selected terms to make sure they are for the language selected on the page. If the language is incorrect then update the term to the correct language.

  • You are attempting to filter the where clause for posts, the “post_where” hook is not called when getting users.

    To get users you would need to modify the WP_User_Query, but this class in WP does not have an equivalent hook to allow you to alter the WHERE part of the query.

    In any event, this would not work because the field you are trying to look at is on the POST and not on the USER and you cannot filter users by a value that is not associated with users.

    To get a list of users that are selected in a field on the post you would need to

    1) Loop over all the flex rows and compile a list of the selected usres
    2) Query the DB (_postmeta table) directly using $wpdp the get and then compile a list of users selected.

  • When ACF gets the reference (field key) it uses the post ID supplied and the field name supplied to get the hidden ACF field key reference. There are only two ways that this can return the key reverence for a different post/post type.

    1) The post ID supplied is incorrect
    2) The field key reference is the database for them meta key/post ID pair is the wrong field key

    Another possibility is that these repeater fields have the same field key. Field keys must be unique. If they are the same then ACF could be getting the definition of the wrong field. But this does not seem likely since you since you are not having a problem in the admin.

  • @hube2 thanks for your response.

    Yes, I am passing the correct post ID in the update_row() function. It’s all happening in the backend using a webhook. I built a plugin to dynamically create posts and update ACF fields.

    So the problem occurred, when I duplicated the field group for “post type A” and renamed it for “post type B”. I ensured that the location is unique. Now, every time when the plugin dynamically creates a post in “post type A”, basically uses the repeater field from the “post type B”. This does not happen when I manually create a post from WP admin.

    I believe that because the field group for “post type B” was created later, update_row() is somehow picking the _products field key from “post type B” instead of the correct “post type A”.

    Here’s the code if it can help:

    
    $images = isset( $data['images'] ) ? $data['images'] : array();
    $post_id = isset( $data['post_id'] ) ? $data['post_id'] : '';
    $swingline_id = isset( $data['swingline_id'] ) ? $data['swingline_id'] : '';
    $acf_key = isset( $data['acf_key'] ) ? $data['acf_key'] : '';
    $acf_repeater_key_values = isset( $data['acf_repeater_key_values'] ) ? $data['acf_repeater_key_values'] : '';
    $row_index = isset( $data['row_index'] ) ? $data['row_index'] : 1;
    
    $new_images = $this->helpers->upload_images( $images, $post_id, $swingline_id );
    
    if ( ! empty( $new_images ) && is_array( $new_images ) ) {
    	$acf_repeater_key_values['_images'] = $new_images;
    }
    
    $updated = update_row( $acf_key, $row_index, $acf_repeater_key_values, $post_id );
    

    I hope this helps to understand the problem. I really think it’s a bug which ACF devs should look into. I can help with more details if needed.

  • unfortunately there is not a lot of documentation on customizing toolbars in the ACF WYSIWYG field. What does exist is here https://www.advancedcustomfields.com/resources/customize-the-wysiwyg-toolbars/

    You might try one of the results provided in this searh https://www.google.com/search?q=acf+add+controls+to+basic+wysiwyg+field

  • Yes, just like @elardael said. You would add this as a parameter in to acf_add_options_sub_page or acf_add_options_page.

    add_action('acf/init', function() {
    	if (function_exists('acf_add_options_sub_page')) {
    
    		acf_add_options_sub_page(array(
    			'post_id'     => 'unique_id',
    			'menu_title'   	 => 'Event Settings',
    			'parent_slug'    => 'edit.php?post_type=events',
    		));
    
    		acf_add_options_sub_page(array(
    			'post_id'     => 'another_unique_id',
    			'menu_title'   	 => 'Cookie Settings',
    			'parent_slug'    => 'edit.php?post_type=cookies',
    		));
    
    	}
    );

    This would allow you to be more certain and specific when getting fields from option pages. Rather than using get_field('field_name', 'options'); you can type get_field('field_name', 'unique_id'); and be certain that the field is from that specific options page.

    Now you can also have field names with the same name on different option pages, not possible if you don’t register a post_id.

    Also, as mentioned before you, can get all fields from an entire options page; get_fields('unique_id');

  • I have found a workaround here

  • I am not sure why this is still an issue and can only apologise for not requiring (pardon the pun) this feature earlier.

    The issue is due to the Validation not accepting anything but directly assigned fields, it ignores acf_blocks_{UNIQUE_ID}.

    So… Until ACF Dev updates the core code, add the below snippet to functions.php as a workaround. DEMO

    
    add_action( 'acf/validate_save_post', '_validate_save_post', 5 );
    function _validate_save_post() {
    
        // bail early if no $_POST
        $acf = false;
        foreach($_POST as $key => $value) {
            if (strpos($key, 'acf') === 0) {
                if (! empty( $_POST[$key] ) ) {
                    acf_validate_values( $_POST[$key], $key);
                }
            }
        }
    }
    
Viewing 25 results - 4,126 through 4,150 (of 21,340 total)