Support

Account

Forum Replies Created

  • You can use sub fields from a repeater in a shortcode or in place that use a shortcode, but you need to use the full meta_key value of the sub field which looks like this: {$repeater_name}_{$row_index}_{$sub_field_name}
    row indexes start at 0

  • There are only two things I can think of. 1 is that the scripts aren’t being adding and 2 is that something about your additions are causing it to not work. Are you getting any JS errors?

  • you can hook into the query used by ACF using this hook https://www.advancedcustomfields.com/resources/acf-fields-relationship-query/

    Altering what the search is searching on the other hand is a different story.

    Let’s say that you wanted to alter every search performed by an acf relationship field, please not, that the following is only a basic outline of where you might start based on what I know.

    
    // add a filter that will run when a relationship query is being done
    add_filter('acf/fields/relationship/query', 'add_acf_relationship_pre_get_posts_filter', 10, 3);
    function add_acf_relationship_pre_get_posts_filter($args, $field, $post_id) {
      // this filter does not really do anything
      // it runs just before acf does the query
      // so that we can hook a pre_get_posts filter
      // only when acf is doing a query for a relationship field
      add_filter('pre_get_posts', 'acf_relationship_pre_get_posts_filter');
      return $args;
    }
    
    function acf_relationship_pre_get_posts_filter($query) {
      // remove this filter so it will not run again
      remove_filter('pre_get_posts', 'acf_relationship_pre_get_posts_filter');
      if ($query->is_search()) {
        // modify the query?
      }
    }
    

    Also, you’re going to need to alter the where statement of the sql query and you may need to add another filter for this that also gets removed when it it run, you should see this https://presscustomizr.com/snippet/three-techniques-to-alter-the-query-in-wordpress/ and maybe this http://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/

  • There are several problems with doing this.

    The first is that I don’t think you can extend an existing ACF field in this way, but I’ve never tried so I can’t really say and I don’t know of any examples where this has been done.

    The second is that even if you do extend the field there is nowhere in the database for ACF to store these values. An ACF image field stores only the image ID value of the image. Adding inputs to a field that are filled in when editing a page will not cause these values to actually be stored anywhere unless you add code that will take those values and store them in some way.

    The only way that you’ll be able to do this is to build a new field type from scratch https://www.advancedcustomfields.com/resources/creating-a-new-field-type/. You can start by copying the existing image field and you’ll need to add your new information and then store the image ID plus your new values as an array of values instead of just storing the image ID. In acf each field has only one value stored in the database.

  • The page you are redirected to will never contain _POST values. A form submission causes 2 server requests, the first to process the form, this includes the _POST values and the second to get the page you are redirecting to.

    It may contain $_GET['thank-you'] but you may need to give your query parameter a value… I’m not sure

    
    'return'       => get_the_permalink(get_the_ID()).'?thank-you=1',
    
  • There isn’t any way to tell what you are referring to by looking at these pages.

    But, generally you can tell if you are on a page 2/3/etc using this function https://codex.wordpress.org/Function_Reference/is_paged

  • is_post_type() is not a WP function

    
    if (get_post_type($post_object->ID) == 'your-post-type') {
    
    }
    
  • This is part of the documentation, not spelled out exact terms, but that is what this means:

    … To allow the form to save data, you will need to place the acf_form_head() function at the top of your page template before any HTML is rendered.

  • The old field returned a single value (string). Any posts that have not been updated will continue to return a single value. A radio field can only have one value.

    Any post updated or added after the change will return an array of values. A checkbox field can hold multiple values.

    You will need to check for both conditions and something different for each. Either that or you will need to edit every existing post to update the field so that it will always return an array.

    I haven’t got a clue how to incorporate any of this into twig because I don’t use it.

  • I just looked at the ACF code and it appears it allows more granular control for ratio fields, at least that’s the way it appears.

    
    function my_acf_prepare_field( $field ) {
       $field['disabled'] = array(
          // set each value option you want to disable
          'value1',
          'value2',
          // etc
       );
       return $field;
    }
    add_filter('acf/prepare_field', 'my_acf_prepare_field');
    
  • I’m pretty sure you can set a field to disabled https://www.advancedcustomfields.com/resources/acf-prepare_field/

    
    $field['disabled'] = true;
    

    but I am not entirely sure at the moment.

  • I am assuming that you’re using the prepare_field hook. In this case the values for the field have been adjusted, you’re hooking in just before the field is displayed. They may also be adjusted before the render_field hook as well, I don’t honestly remember. In this case there isn’t really any documentation on what the fields attributes might hold. I do know that _name is a temporary field that holds the real field name and name is altered to hold what will be put into the name attribute of the field.

    For me it’s just easier and faster to output the field’s settings so I can look at it rather than look up any documentation if it exists.

  • I’m not the developer, but one thing I can probably safely say is that Elliot is not going to add something that can be easily broken. Also, right now when ACF generates field keys it uses uniqid() which just generates a string based on the current time.

    To auto generate unique keys that will not change, ACF would need to know the parent, whatever that might be.

    You might want to bring this up with the developer by contacting him here https://www.advancedcustomfields.com/contact/

    I would create a function that takes a prefix/suffix for a field key

    
    function custom_add_field($prefix) {
      $field = array(
        'key' => 'field_'.$prefix.'_12345678',
        //.....
      );
    }
    

    You might want to look into the way the ACF generates field keys for clone fields.

  • I don’t see where acf_form() is called inside the form tags, what am I missing?

  • You can use ‘get_field_object($field_key)` to see if a field is already defined. However, as I mentioned in your other topic, this will not work if a field has not already been defined in some other php code and will be defined later.

  • The main issue I’ve run into when doing this is that the key must remain the same for each instance. Field keys can be dynamically generated, but once they are for a specific field they must then remain the same forever. What happens when you remove one, then some dynamic value changes and all the keys end up different. Or maybe you add a new one that gets generated before one that is already added and the field keys for the new one use the field keys for the old one and the old fields get new keys. When generating fields using PHP you also cannot depend on the field being defined already so you can’t even use get_field_object($field_key) to see if it has been defined already.

    Not only do field keys need to be unique and never change, but depending on where you’re adding the fields, the field names may also need to be unique and never change. The only time you can safely repeat a field name is if that field is a sub field of a repeater, flex or group field.

  • acf_form() needs to be called somewhere inside the <form ...></form>

  • Radio fields do not support readonly. It’s not ACF, it is the way that radio fields work. https://stackoverflow.com/questions/1953017/why-cant-radio-buttons-be-readonly

  • Try using field['_name'] instead of $field['name']

    You can see all the values for a field in your filter by adding the following to the start of your filter in order to see what values you may want to use.

    
    echo '<pre>'; print_r($field); echo '</pre>';
    
  • The code I originally posted was not 100%, I missed an error when copying your original code

    
    add_action('wp_ajax_email_sender', 'email_sender');
    function email_sender($field) {
       // move this to the top
        $post_id = $_POST["post_id"];
    
        if( have_rows('day_repeater', $post_id) ):
            // loop through the rows of data
            while ( have_rows('day_repeater', $post_id) ) : the_row();
    
            $date = get_sub_field('date'); // I need values from this field
            
                // LOOP FOR NESTED REPEATER FIELD
                if ( get_field('accommondation') ):
                   // next line changed
                    while( have_rows('accommondation') ) : the_row();
                    
                    $notes = the_sub_field('notes'); // I need values from this field
    
                    endwhile;
                endif;
            endwhile;
        endif;
    

    There isn’t really a way to get the specific row other than to get the values from that row using JavaScript and submit them as part of your ajax request.

  • Why are you worried about this?

    Are you using front end forms?

    Do you have people in your admin that you do not trust?

    On top of this the article is at over 4 years old. ACF currently does more escaping. I can’t see anything in the first links that you posted, so I don’t know what you’re really talking about.

  • The filter that you are trying to use only works in the admin when selecting posts, it does nothing on the front end of the site. On the front end ACF always orders the posts in the order select. If you want to have a different order then you need to do your own query on the posts. Get the field without formatting and then use that in the post__in argument for WP_Query().

    
    // get unformatted value
    // will return an array of post IDs
    $post__in = get_field('post_object_field', false, false);
    
  • What is triggering the jquery to run? What element have you attached your JS to.

    When using js you need to use field keys

    What you need to do is find the current row.

    
    // element represents an field 
    var row = element.closest('acf-row');
    

    one you have the row then you find a field in the row, I a assuming a field of type “input”

    
    var field = row.find('[data-key="your field key"] .acf-input input');
    
  • The page link field does not have a text component, you would usually use another field to allow entry of the link text. https://www.advancedcustomfields.com/resources/page-link/

  • acf/render_field is used to show additional content either before or after the field. You can access information about the field during the filter

    
    add_action('acf/render_field', 'show_field_details', 1);
    function show_field_details($field) {
      echo '<p>',$field['name'],' ',$field['key'],'</p>';
    }
    

    You could also use acf/prepare_field to modify all the labels https://www.advancedcustomfields.com/resources/acf-prepare_field/

    
    add_filter('acf/prepare_field', 'show_field_details', 1);
    function show_field_details($field) {
      $field['label'] .= '<br />'.$field['name'];
      return $field;
    }
    
Viewing 25 posts - 1 through 25 (of 8,541 total)

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.