Support

Account

Forum Replies Created

  • When you hover over the input there should be a + on the right side of the field. Click that to add a term.

  • There is an error in my code I gave you

    This line should be causing an error in php

    
    $term_id = intval(str_replace('term_', $post_id));
    

    it should be

    
    $term_id = intval(str_replace('term_', '', $post_id));
    

    I also set up a test using posts and categories, this is working as expected

    
    add_filter('acf/save_post', 'category_list_save', 20, 1);
    function category_list_save($post_id) {
      $posts = get_field('posts', $post_id);
      $term_id = intval(str_replace('term_', '', $post_id));
      if ($posts) {
        foreach ($posts as $post) {
          // make sure "list" is the taxonomy name and not the term name
          wp_set_post_terms($post->ID, $term_id, 'category', true);
        }
      }
    }
    

    It it’s still not working for you make sure that your taxonomy and post type are attached. https://codex.wordpress.org/Function_Reference/register_taxonomy_for_object_type

  • The reason this happened is because you deleted the field and created it again. This caused the ACF field key reference for any values saved to the field to be incorrect, it points to the old field key that no longer exists. Because of this ACF does not know what to do with the value stored in the database so it returns what is stored without formatting it. The only way to fix this is to update all the field key references, which means that you need to update all posts,

    Or you can alter it by doing a query on the DB
    UPDATE wp_postmeta SET meta_value = "NEW FIELD KEY" WHERE meta_value = "OLD FIELD KEY"

    Please back up your DB before making changes like this.

  • 
    update_field('field_5d3737638274e', array($user_id), $request_id); 
    
  • Try altering your if syntax to use if (){...} else {...} instead of if():... else:... endif;

  • To answer the question by @squarestarmedia

    No, this is not possible. When you are editing a field group ACF does not know what data in the database is saved using the field. In addition to this, when the group is saved, ACF does not know that the field use to be a top level field and is now nested in a repeater (or visa-versa). Nor does in know if you’ve changed to location rules of the group.

    The data stored for a field is related to a post or some other object.

    The field group is not related to anything. The fields in the group are related to the group.

    In order to associate the field to the data when getting or saving a post (or other object) ACF needs 2 important pieces of information the first is the post ID and the second is the field key. ACF has the field key when saving a field group, but it does not have the post IDS for every post the a value is saved to.

  • I don’t see any reason why it shouldn’t be working, the only thing that I can think of is that you need to use the term slug instead of the ID when calling wp_set_post_terms(), but I don’t know why.

  • The other issue that could be happening is that the ID of the image has changed from one site to the other. If you used a standard export/import to move things then the post IDs on the new site will not match the post IDs on the old site. When moving a site you must ensure that all posts maintain the same IDs and this cannot be don by exporting and importing, you’ve basically got to copy the DB as is.

    Again, this comes down to how the site was migrated.

  • The problem is that the ACF field key reference is missing in the DB, or the field key reference is wrong. How did you migrate the site?

    Every field has 2 entries in the meta table

    
    meta_key       | meta_value
    {$field_name}  | value
    _{$field_name} | acf field key
    

    without the second entry ACF does not know what to do with the value in the first entry

  • You can’t use the field name, you need to use the field key. Fields are not identified in the DOM by name. Names can be duplicated, field keys are unique.

  • Not exactly like that, but you can alter the layout title https://www.advancedcustomfields.com/resources/acf-fields-flexible_content-layout_title/

  • There is nothing built into ACF that will do this for you and I don’t know of any examples of it being done. The problem is finding the fields with the values and correctly updating the repeater in a way that will not break the repeater.

    I would create an acf/load_value filter for the repeater https://www.advancedcustomfields.com/resources/acf-load_value/

    
    add_filter('acf/load_value/name=REPEATER_NAME', 'remove_invalid_posts', 20, 3);
    function remove_invalid_posts($value, $post_id, $field) {
      if (empty($value)) {
        return $value;
      }
      foreach ($value as $index => $row) {
        // your need to use field keys here I think, but you'll need to test
        $related_post = $rows['field_1234567']; // field key of relationship field
        $post = get_post($related_post);
        // I am just seeing if a post is returned here
        // you could be more thorough, 
        // for example testing to see it it's in the trash or whatever if it exists
        if (!$post) {
          unset($value[$index];
        }
      }
      return $value;
    }
    
  • I looked into the code, the date field does not work with setting $field['default_value']. You need to use this https://www.advancedcustomfields.com/resources/javascript-api/#filters-date_picker_args

    I do not know the correct code you need to use here to set the date, you will need to look at the jquery date picker docs here https://api.jqueryui.com/datepicker/

  • There are times when ACF is useful and there are times when something else is a better choice. If I wanted to create a CPT that I could filter based on geo location I would likely use https://www.wpgmaps.com/purchase-professional-version/

  • This is not a bug, but the intended operation.

    When a field is conditional and it does not appear, that fields value is not changed. It is not changed because the field in not submitted.

    ACF does not look at field 1 to see if the conditions are met when saving field 2. The condition is on field 2. ACF has no idea when a field is save what other fields might be conditional base on the value of the field being saved.

    In your template code you need to do the work something like this.

    
    if (get_field('field#1') == 'A) {
      echo get_field('field#2');
    }
    

    There have been many discussions on these forums about this. Some like this, some do not. With the way it operates, if a user changes the value and saves the post, if they should change their mind later then the value entered into field 2 will not need to be re-entered.

    The only way around this is to create an acf/save_post filter https://www.advancedcustomfields.com/resources/acf-save_post/

    
    add_filter('acf/save_post', 'my_save_post_function_name');
    function my_save_post_function_name($post_id) {
      if (get_field('field#1', $post_id) != 'A') {
        delete_field('field#2', $post_id);
      }
    }
    
  • The short answer is that you can’t.

    The long answer: Each row is a row in the repeater and the code for the repeater does not allow switching a row of the repeater to be represented as a table column. In order to do this you’d need to build a new repeater field as well as all the JavaScript that’s implemented when a new row is added. Possible, but if this was easy my guess is that it would already be included.

  • Fields are not automatically synced. The fields in the JSON files will be loaded before the fields in the database, thus overriding what is in the DB.

    The only time that this is not the case is when you edit a field group. When you edit the field group then it is loaded from the DB and the JSON file is ignored. This is why you need to sync the group before you make any changes to it in the admin.

  • 
    get_field('site_link', $post_id);
    

    The first argument for get field is the field name, second is the post ID, this is reverse of get_post_meta()

  • Try

    
    $field['default_value'] = date('Ymd');
    
  • Date fields in ACF are not stored in standard SQL date format, which is seems you are aware of looking at this line of your code $today = date('Ymd'); and this is the reason your query is getting no results. Change the type of the meta field to either ‘NUMERIC’ or let it default to ‘CHAR’.

  • There are explanations of ways that you can sort a repeater on this page https://www.advancedcustomfields.com/resources/how-to-sorting-a-repeater-field/

  • [acf field="test"]

    https://www.advancedcustomfields.com/resources/shortcode/

  • The pen button opens the standard WP edit screen for the file. This works the same as if you went to the media folder and opened the WP editor for it from there. You can’t delete the button, but you can probably hide it with some custom CSS added to the admin of your site.

Viewing 25 posts - 1 through 25 (of 8,688 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.