Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Hello, I’ve fixed @nerd-attack solution for drag&drop also arrays like gallery field etc.

    
    // acf drag n drop flexible layouts between repeaters
    add_action('acf/input/admin_footer', function () {
        ?>
        <script type="text/javascript">
    
            (function($) {
    
                acf.add_action('ready', function($el){
                    $(".values").sortable({
                        connectWith: ".values",
                        start: function(event, ui) {
                            acf.do_action('sortstart', ui.item, ui.placeholder);
                        },
                        stop: function(event, ui) {
                            acf.do_action('sortstop', ui.item, ui.placeholder);
                            $(this).find('.mce-tinymce').each(function() {
                                tinyMCE.execCommand('mceRemoveControl', true, $(this).attr('id'));
                                tinyMCE.execCommand('mceAddControl', true, $(this).attr('id'));
                            });
                        }
                    });
                });
    
                acf.add_action('sortstop', function ($el) {
    
    		// check if the dropped element is within a repeater field
    		if ($($el).parents('.acf-input > .acf-repeater').length) {
    
    			// get column_num from closest acf-row
    			var column_num = $($el).closest('.acf-row').attr('data-id');
    
    			// loop all (input) fields within dropped element and change / fix name
    			$($el).find('[name^="acf[field_"]').each(function () {
    				var field_name = $(this).attr('name');
    				field_name = field_name.match(/\[([a-zA-Z0-9_-]+\])/g); // split name attribute
    				field_name[1] = '[' + column_num + ']'; // set the new row name
    				var new_name = 'acf' + field_name.join('');
    				$(this).attr('name', new_name);
    			});
    
    			// get closest flexible-content-field and loop all layouts within this flexible-content-field
    			$($el).closest('.acf-field.acf-field-flexible-content').find('.acf-input > .acf-flexible-content > .values > .layout').each(function (index) {
    
    				// update order number
    				$(this).find('.acf-fc-layout-order:first').html(index + 1);
    
    				// loop all (input) fields within dropped element and change / fix name
    				$(this).find('[name^="acf[field_"]').each(function () {
    					var field_name = $(this).attr('name');
    					var is_array = field_name.endsWith('[]')
    					field_name = field_name.match(/\[([a-zA-Z0-9_-]+\])/g); // split name attribute
    					var tempIndex = parseInt(field_name[3].match(/([0-9]+)/g)); // hacky code
    					field_name[3] = field_name[3].replace(tempIndex, index); // set the new index
    					var new_name = 'acf' + field_name.join('');
    
    					$(this).attr('name', new_name + is_array ? '[]' : '');
    				});
    
    				// click already selected buttons to trigger conditional logics
    				$(this).find('.acf-button-group label.selected').trigger('click');
    			});
    		}
    	});
    
            })(jQuery);
    
        </script>
        <?php
    });
    
  • @jeremy_fcinq based on your approach I was thinking about using about either using:

    return wp.blocks.createBlock('acf/owl-link', atts); – so with passing the some attributes as data

    or using blocks.switchToBlockType.transformedBlock filter and overriding the attributes data.

    Sadly they both didn’t worked :/ But I still think this is a valid – creating the ACF block with parameters – I just can’t find the way how to do this.

  • It is possible to query customs fields created manually in php.
    You have to use the “full path” of the fieldname including the groupname.

    
    'meta_query' => array(
       array(
             'key' => 'event_details_event_startdate',
             'value' => $today,
             'compare' => '>='
      )
    )
    
  • Hi @dreiqbik

    If you are experiencing preview / draft issues with the classic editor, this is unexpected behavior. Can you please submit a full bug report to our support team?

    https://www.advancedcustomfields.com/contact/

  • Hi,

    Put this in your child theme functions.php file :

    function jl_insert_term_if_not_exists($term, $taxonomy) {
        if (empty($term) || is_numeric($term)) {
            return $term;
        }
    
        if ($result = term_exists($term, $taxonomy)) {
            return $result['term_id'];
        }
    
        $result = wp_insert_term($term, $taxonomy);
    
        if (!is_wp_error($result)) {
            return $result['term_id'];
        }
    }
    
    function jl_acf_update_value( $value, $post_id, $field ) {
        if ($field['type'] == 'taxonomy'
            && in_array($field['field_type'], array('select', 'multi_select'))
            && strpos($field['wrapper']['class'], 'acf-select-tags') !== false)
        {
            if (!is_array($value)) {
                if ($term_id = jl_insert_term_if_not_exists($value, $field['taxonomy'])) {
                    $value = $term_id;
                }
            } else {
                foreach ($value as &$item_value) {
                    if ($term_id = jl_insert_term_if_not_exists($item_value, $field['taxonomy'])) {
                        $item_value = $term_id;
                    }
                }
            }
        }
    
        return $value;
    }
    add_filter('acf/update_value', 'jl_acf_update_value', 5, 3);
    
    function jl_acf_input_admin_footer() {
    ?>
    <script type="text/javascript">
        (function($) {
            acf.add_filter('select2_args', function( args, $select, settings, $field ){
                if ($field.hasClass('acf-select-tags')) {
                    args.tags = true
                }
    
                return args;
            });
        })(jQuery);
    </script>
    <?php
    }
    add_action('acf/input/admin_footer', 'jl_acf_input_admin_footer');

    If you want to enable the select2 “tags” function (add with enter key) go in your Taxonomy field (select or multi-select type) options, in wrapper / class, set “acf-select-tags”.

    Hope this helps.

    PS : Then, you can disable the “can create terms” option if you want to get rid of the “plus” button.

  • Hi,
    i have a similar problem:

    I have a custom post type with different taxonomies.

    I want to check for a custom field within a site, which holds the taxonomy name from the custom posts. So i can enter the taxonomy in an ACF field on top of each site, and the loop should output all posts within that taxonomy i’ve entered. But it seems not to work, and my coding skills are poor…

    “kategorie_eintragen” is my taxonomy ACF field for the sites, i’ve added these taxonomies before within my custom post type “touren”.

    Here my code from the page template:

    					<div class="videos">
    
    						<?php 
    
    						// get posts
    						$kategorie = get_field('kategorie_eintragen');
    						$posts = get_posts(array(
    							'post_type'			=> 'touren',
    							'posts_per_page'	=> -1,
    							'post_status' 		=> 'publish',
    							'orderby' 			=> 'date',
    							'order'				=> 'ASC',
    							'tax_query' => array(
    								array(
    									'taxonomy' => 'kategorie_eintragen',
    									'terms' => $kategorie,
    								)
    							)
    						));
    
    						if( $posts ): ?>
    
    							<?php foreach( $posts as $post ): 
    
    								setup_postdata( $post ) ?>
    						
    								<article id="post-<?php the_ID(); ?>" class="post-<?php the_ID(); ?> post type-post status-publish format-standard">
    								<a href="<?php the_field('link_zur_tour'); ?>">
    								<div class="videos-title aktiv-bild">
    									<?php 
    									$image = get_field('bild_der_tour');
    									$size = 'oberkategorien'; // (thumbnail, medium, large, full or custom size)
    									if( $image ) {
    										echo wp_get_attachment_image( $image, $size );
    									} ?>
    									<h2><?php the_field('titel_der_tour'); ?></h2>
    								</div>
    								</a>
    								</article>
    						
    							<?php endforeach; ?>
    
    							<?php wp_reset_postdata(); ?>
    
    						<?php endif; ?>		
    						
    					</div>

    How do i make the loop query these custom post types only within the taxonomy i gave him on the current site?

  • As for the developer not being here, he does not visit the forums much if at all. That’s why I’m here so that he can devote more time to working on ACF. I do my best to answer what I can and hope that other users can answer the questions I can’t. The support tickets submitted go to other people, and unfortunately I think that E is not having much luck at keeping skilled people to help him there, so he’s dealing with those himself the way he used to deal with this forum himself until I came along. This is likely why it takes so much time to get responses to tickets. I imagine that he get many of them every day and can’t keep up.

    To answer, why not go that way with the repeater field. This would mean treating a text field in a repeater differently than a text field that isn’t in a repeater. The repeater is just a wrapper that creates recursion. The only difference in ACF between these two things is that the one in the repeater has a parent field and the field name is prefixed when saving to the DB. This is what gives ACF the ability to nest fields infinitely. Without recursion it would be much more complicated to accomplish this.

  • Hi John,

    Thank you for your response. I appreciate it. I’ve seen you being very active on the forums. Actually much more active than the developer himself.

    1. I understand the reason for the second meta field. I know ACF stores that specific extra little information there. I’m just curious why this approach was taken instead of some sort of a pure PHP registry that would store this information and would not require this database bloat. I’d love to get some insight from the developer here. I’m not saying this is bad, I’m just trying to learn and understand the reasoning behind it. There is no information about it in the docs.

    2. Yeah, I’m aware of that but if we go this way, we can say the same about the Repeater field: why not store the entire “Repeater” field as a serialized meta? It would just be a single meta field update operation. Instead of that, if you have a Repeater field consisting of 10 fields and you create 20 entries with it, you end up with 200 meta fields to update. And that’s only one repeater field. Imagine you have 5 of those. Yeah, you end up with 1000 meta fields per single post.

    I’m trying to understand why such a “separate fields” approach was taken for the repeater but not for the other fields? I wouldn’t be asking if either one or the other was used for every case, consistently – but it’s not the case. I’m really curious about it as I want to learn the concept so I can use the plugin with full confidence for my clients.

    And thank you for posting the snippet: I’m perfectly fine writing my own code but I truly want to use the plugin for meta box management as it is, without a need to do any sort of hacking for such core functionality as the data storage type.

    If there is good reasoning for all of the above, I’d LOVE to learn and get to know it. Whether it’s about the backward compatibility or something else, it would be good to know.

    Thank you so much.

    PS. I’m a little worried about the recent activity of the plugin developer. Based on Elliot’s profile, I can see the forum replies count varies between 1-2 per month. I understand the support is being taken care by the support ticket system but I have posted there regarding a different issue and haven’t got any response for 4 days now. I’m a bit worried about the state of this matter?

  • I am not the developer, just a long time user that has gotten to know the workings of ACF. If you really want to get the developer to weight in then you’ll need to submit a request here https://www.advancedcustomfields.com/contact/

    1) The reason that there is a field key for each field is so that ACF knows how to treat that field value. The issue is that any field name can be repeated. Let’s say that you have a field named “some_field”, this is a simple text field and the data of this field is save for a “Post”. Now let’s say that you create another field with an identical name and you save this field value to “Pages” but is field is a relationship field. The only way that ACF knows how to treat these two fields differently and return the correct value is that each of the fields has a different field key reference.

    Many people are under the mistaken impression that ACF “knows” or “remembers” what fields are used for what post type, taxonomy, user, options page, etc. It does not. When ACF gets or saves a value two pieces of information are required, the post ID (or some other object ID) and the field key. When you are saving a value ACF has this information when the form is submitted. When retrieving a value when you use the field name ACF must look up the correct field key.

    This is the reason that a field key reference is needed. The only way that this would not be the case would be if ACF required a unique field name for every field created.

    2) Fields are stored separately, values in those fields are not always stored as separate values. A selection in a gallery field is not a sub field of the gallery.

    So it might be possible to store the values of a gallery field in multiple entries. This would require deleting all values before updating. Then ACF would need to loop over the values and insert each. This action of deleting and then adding multiple entries could cause a performance issue in the admin. Imagine that you have 20 fields like this and each of these fields has 20 entries. This would do a total of more than 400 queries to insert the values. This is because of the way that WP meta values work.

    Another issue with doing this at this point would be backwards compatibility. Changing the way ACF stores the values now would be difficult.

    There are ways to overcome the issues with doing “LIKE” queries on meta values. You can see how I overcome this by reading the post I created here…. well, it seems that site is now gone….

    Anyway, the idea behind what I wrote is to convert fields that you want to query by to standard ACF field. For example, lets say that I have a checkbox field and the checkbox field has values that I want to query by.

    
    add_filter('acf/update_value/name=my_checkbox_field", "convert_my_ck_to_wp", 20, 3);
    function convert_my_ck_to_wp($values, $post_id, $field) {
      $search_field_name = 'my_checkbox_field_wp';
      delete_post_meta($post_id, $search_field_name);
      if (is_array($values)) {
        foreach ($values as $value) {
          add_post_meta($post_id, $search_field_name, $value, false);
        }
      }
      return $values;
    }
    

    Now a query can be done using the alternate field name. This does create extra data in the database, but this is not nearly as detrimental to queries as doing a “LIKE” query on the ACF value. And since we only do this on fields where we need the values stored this way there is less likelihood of the performance issues we might have if every ACF field was stored in this manner.

  • Another solution could be to define a conditional logic.

    if field1 “value is equal to” true && field1 “value is equal to” false

  • There isn’t a way to use function to get ACF values from a separate WP installation. You’ll need to build a separate application either by doing DB queries directly on the DB for the other site or by using some type of API an possibly CURL to get the values from the other site.

  • thank you for your reply, I understood your explanation, but even using your code, unfortunately if I don’t manually specify the parameter post_id into the shortcode squares, it will not render into the visual builder. Honestly I think that I have to retrieve the post id from some sort of ajax call to make it works in the visual builder, cause I think that this code

    $post_id = $_POST['et_post_id'] ;

    is related to this ajax call

    ajax

    but it is difficoult for me to find a way out, this is for sure related to how divi passes the current post_id to shortcodes

  • I am having the exact same problem with my multisite. Everything works well in the back-end, but when I try to use front-end form to create a new post, post object field doesn’t populate any choices. Or if I choose something and save it from back-end, it only shows that selected option on the front-end.

    Other fields that use select2 (user field etc.) also doesn’t populate any choices on the front-end form.

    I am using acf_form function

    I am using wordpress 5.4 and ACF 5.8.9

    *I don’t have any JS errors on console
    *I don’t have any PHP errors on WP_DEBUG
    *I tried to disable all other plugins but that didn’t work either
    *I tried every possible placement of wp_footer and acf_form_head to give best priority to loading of acf components
    *my custom theme doesn’t contain any other AJAX requests
    *I read all forum threads and google search results about similiar errors.

    Still couldn’t find an answer.

  • Sooo, i finally managed to found a way of achieve this.

    First, you need to modify the way you register the block in ACF.
    You’ll have to add “transform” in your acf_register_block() call
    (All the needed code is in the Gist)

    Then, the PHP will pass your transformers “transform” method as a string, not a callable function, so we need to convert it.

    https://developer.wordpress.org/block-editor/developers/block-api/block-registration/#transforms-optional

    For that i use javascript
    (You’ll need to load a javascript file in the backend, and compile the ES6 if you want to write ES6 as in my code sample, but it’s not the point)

    So in Javascript, first thing : I prepare a global object with my transformers method (same name as in the PHP), and in the hook, -I look for my ACF block with transforms informations, and convert the string into the function with the same name.

    Then, in my transformer function, I receive an object with the string content, and there it is the ugliest part, (I don’t find any solution to pass content directly to the createBlock method for ACF block, maybe ACF can tell us?)
    I use a setInterval to wait the ACF block is loaded in the DOM and I put the content into my field.

    You can find all the code here:
    https://gist.github.com/jeremypetrequin/672807361fa6919d597cdbb20b0f67ac

    SO: I know it’s an ugly and hacky way to achieve this, but I didn’t find any other way (except rebuild my Block without ACF but it wasn’t an option) and it seem’s to work.. I imagine for people who know better the ACF & Gutenberg API than me there are some other and better ways to do..

  • Thank you. I don’t understand why a user can not edit his own field. It is non-sense.

    Anyway, where can I do that? The field attributes of “file” are:
    Field Label
    This is the name which will appear on the EDIT page

    Field Name

    Field Type

    Instructions

    Required?

    Return Value

    Library

    Minimum

    Maximum

    Allowed file types

    Conditional Logic

    Wrapper Attributes

    I don’t see anything about access rights. Could you help me please?

  • 
    // post ID in second arg
    // false in 3rd arg gets the unformatted value
    // this will return an array in the order that the images
    // are in the gallery
    $gallery = get_field('your-gallery-field', $post_id, false);
    // use this array to query the attachments
    $query = new WP_Query(array(
      // other query arguments
      'post__in' => $gallery,
      'orderby' => 'post__in'
    ));
    
  • I do this, but I do it manually.

    The first thing that I do is create a text field that will hold my unique ID.

    Then I make that field readonly

    
    add_filter('acf/prepare_field/key=field_XXXXXXX', /* field key of the text field */ function($field) {
      $field['readonly'] = true;
      return $field;
    });
    

    Then I create an acf/save_post filter that updates the field with a unique ID value

    
    add_action('acf/save_post', function($post_id) {
      // do whatever you need to get a field value
      // how you do this is dependent on how your fields
      // so there is no specific example
      // test the value of your id field to see if it is empty
      // if it is then generate a unique ID
      // sleep 1 second to ensure the value is unique
      sleep(1);
      // generate unique ID
      // https://www.php.net/manual/en/function.uniqid.php
      $id = uniqid('row-');
      // update the field with the new ID.
    });
    

    Or you could simple add a text field and allow them to enter their own ID, but then you have to worry about it they are entering something unique or not.

    In either case, then what you need to do is to alter your HTML code output to add this id to the element

    
    <div id="<?php the_field('your_field_name'); ?>">
      your content here
    </div>
    
  • I am not the developer, but I’ve been using ACf for a very long time.

    In general, the reason that ACF stores all fields as separate entities is that ACF is only an admin tool and the ACF function are just wrappers for the build in WP function for meta and options values used for getting add updating these values. So, for example you can actually get the value of an ACF field by using get_post_meta();

    The repeater fields, and all repeater type fields, this includes repeaters, flex fields, and groups, this was done to conform to above and at the same time to allow a way to associate all of the fields on the same row because WP does not provide any way to relate one meta field to another meta field.

    The number of fields may affect front end performance slightly, however, it should not be significant. When WP sets up a post it automatically gets all of the meta values associated with the post in a single query.

    How you code can effect performance, for example, if you do any coding that does a query on the database based on the meta value, this could effect performance because it causes WP to do a “LIKE” query on the meta value.

    Where you will see performance drop off if you have a lot of fields is in the admin when making updates. This is due to the way that WP updates meta values as each field updated creates several queries. I personally do not concern myself with the performance of the admin.

  • This is not possible to do with a shortcode because of the way WP processes shortcodes.

    To be honest, I’m not sure how to fix it but you could try this (switch to single quotes)

    
    <a class="btn ktblocksvideopop" href="[acf field='youtube_url']">Watch Video</span></a>
    
  • Yes already tried and they will told me that is an ACF issue. But I think that is related to DIvi cause I can reproduce the same issue with other shortcodes that requires the page id in visual builder

  • In the meantime I made some researches and found out that the ACF Oembed Field does not seem to cache any of the oembed requests. I already filed a support ticket. 🙂

  • Have the same issue and tried the code above, but its not working. Is ‘shop’ the page slug? I also tried the ID number but that didn’t work either.

    <?php $page_id = wc_get_page_id( 'shop' );
    $your_field = get_field( 'marquee', $page_id );  ?>
  • We have exactly the same problem and that’s because WordPress creates the player via the admin-ajax.php, resulting in that the request to the youtube oembed API comes from your server and not from your computer.

    We host our WordPress Sites ourselves and we have 100+ sites running on our server. Some sites are heavily using ACF oEmbed.

    Because WordPress handles the oembed request itself youtube gets a lot of requests from our server IP and we are hitting the quota limit.

    This is the result of the curl:
    curl https://www.youtube.com/watch?v=egSvdEJZRBk

    <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
    <TITLE>302 Moved</TITLE></HEAD><BODY>
    <H1>302 Moved</H1>
    The document has moved
    <A HREF="https://www.google.com/sorry/index?continue=https://www.youtube.com/watch%3Fv%3DegSvdEJZRBk&q=EhAqAQSIAGYQALAcDF4AAAABGPyv5fQFIhkA8aeDS54ikJN6T6hIAXwP4RDLMyzfx9vjMgFy">here</A>.
    </BODY></HTML>

    My take would be that ACF could enable an option to store the complete oembed response from google in the postmeta instead of only saving the entered url. With this, the frontend does not have to request the youtube oembed api everytime a uncached version of the site is loaded.

    Is this realistic?

  • Hi all,

    Unfortunately, we do not yet have a solution for adding classic metabox preview compatibility with the Gutenberg block editor.

    This new editor does not currently save classic metabox data during the preview request, meaning the preview will fail to load preview data and will most likely appear blank – or in some cases, revert to the last saved draft.

Viewing 25 results - 6,976 through 7,000 (of 21,361 total)