Forum Replies Created

  • Most of what I’m going to say will likely not help you unless you do a lot of work to make it happen.

    A repeater does not store a single value. It creates an entry in the options page for the repeater + an ACF field key reference for the repeater + an option & field key reference for each sub field in each row in the repeater. So let’s say that you have a repeater with 5 sub fields and 100 rows, the total entries in the db will be 5(subfields) * 2 * 100(rows) +2(the repeater) = 5002 options table entries for the repeater. Every call by ACF to get_option() produces multiple queries. To make matters worse, when calling get_fields('options') acf will load every options value it has ever stored for every options page.

    Ways to mitigate many queries for options, most of this needs to be done before a lot of data is input

    1) set autoload to true for the options page

    2) use a custom post ID for your options page like “my-custom-options-slug”. When you do this you will limit the queries for “get_fields()” to a limited number of db entries. The reason is that the “option_name” in the DB will be prefixed by this slug. Otherwise every “option” saved by ACF will be retrieved no matter what options page they are associated with. This is not something that can be done after data is entered because you need to enter it all again.

    3) An alternate to #2 is to use a post ID value for the options page post ID setting. This causes ACF to save the values in the meta table for a post instead of in the options page making it possible to do a single query for meta values instead of a single query for each value. This has the same downside as #2 after a lot of data is entered into the options page.

    4) You could likely reduce the number of queries on your existing data by not using get_fields() for options and instead use a repeater loop and get specifically what you want. This will limit the number of queries because ACF is not attempting to load every option value saved on every options page. This will help if you have many other options values other than those associated with the repeater.

    5) You can also limit the number of queires by using get_field('repeater-field-name', 'options') as this will cause ACF to only get the fields associated with the repeater, again, instead of trying to get every option value ever saved.

    6) A way to mitigate this issue after the fact would be to use transients You can get the values and store the array in a transient so that then next time you can see if the transient has a value and skip doing the work. This way you can do one DB query to get the entire array.

  • you need the ID and not the title, ACF stores only the ID so when you are showing a manufacturer page you should be able to do

    'meta_value' => $post-ID
  • I don’t think you can move “Posts” as it is a built in post type. You’d need to remove the admin menu for it and move it, but then it would be impossible to nest categeoris, tags and other links. Each post type should have it’s own top level menu.

    You can put a CPT under an options page, i think this should still work

  • Performance should make little difference with 1 function of 2, but you’re doing the same thing, just use the same filter for both fields. Make the code simpler by removing duplicate function.

  • Unfortunately, there really is not an easy way to do this, the only thing that I can do is to tell you what I would do given the same scenario.

    1) I would not delete the repeater

    2) I would create the new fields

    3) I would create a filter ( that runs when the value is loaded for the new fields. If the new field does not have a value (has never been set) then retrieve the corresponding value from the old field. This will work to automatically transfer the old values to the new field when a post is edited.

    4) I would create and action ( In this action I would delete the old fields from each post as it is updated using the new fields.

    5) With #3 & #4 in place and working successfully I would create another filter ( for the repeater to hide the old field (return false). This leaves the old fields and data in place and sill retrievable for #3 and for #6 (coming up)

    6) Alter the template file(s) where the old values are used. First see if the new field has a value and if it does use the new field. If the new field does not have a value then to get the value from the old field and use it.

  • The problem isn’t necessarily that the questions are too hard but that they are outside of the ability of other users or that they all lead to complex projects that would require hours of coding to supply an answer. Beyond what most people are willing to supply without compensation.

    Don’t know if you’ve noticed, while there are some other users helping out around here I am the one that will more than likely answer if I can and have time to do so. While I would like to help more, there is only so much that I can do here on this forum.

    I can’t really point you to any specific developers that you might hire, but there is a link on the support page where the ACF developer recommends looking here

  • There isn’t any way to alter the classes on the field and label elements. Doing so would require writing custom JavaScript.

  • You are correct, this would need to be done with JavaScript and AJAX and it is not really simple enough to supply a code example. I have some examples of doing this type of thing, but nothing that will get you to what you want do very easily

  • You cannot add php code inside of the WP editor, you must alter the templates. WYSIWYG editors are not meant for coding PHP.

  • There really are not any tutorials here on basic template coding for WP.

    Once you have that figured out then showing a field only when it has content is simple.

    For example:
    <strong>PROPRIETARIO:</strong> [acf field="proprietario"]
    in PHP becomes

    if (get_field('proprietario')) {
      ?><strong>PROPRIETARIO:</strong> <?php the_field('proprietario'); ?><br />

    These types of examples for fields can be found in the documentation for each field type.

    Another option would be to build your own shortcode. There are a lot of tutorials on the web for how to built custom shortcodes

    ShortcodesUltimate has a shortcode creator add on to create shortcodes without messing with theme files

  • Your code only partially came through because you didn’t use code tags in your reply.

    You probably need to supply an object type to when calling get_ancestors(), the post type name, and I missed that. what is the post type you’re trying to get the grandparent of?

    If you war asking how to use the image field it is documented here

  • This is not a field key

    $subscription_pickup_location_key = ‘subscription_pickup_location’;

    When updating fields that do not yet exist you must use the field key

  • provide code that’s not working for you.

  • See

    $ancestors = get_ancestors($post_id); // supply correct post ID
    $gp_id = 0;
    if (is_array($ancestors) && count($ancestors) >=2) {
      // has grandparent
      $gp_id = $ancestors[1];
    if ($gp_id) {
      $value = get_field('field-name', $gp_id);
  • You are looking at the html for creating a field and not entering data.

    I did another test and I’m still not seeing any issues with saving values or adding custom values.

    Is your issue with showing the custom values on the front? What code are you using?

      if (get_sub_field('type') == "Image") {
          <div class="full-img">
              $link = get_sub_field('link');
              $content = '<img src="'.get_sub_field('image').'">';
              if ($link) {
                $content = '<a href="'.esc_url($link).'">'.$content.'</a>';
              echo $content;
            <p class="caption"><?php the_sub_field('caption'); ?></p>
  • just add additional lines for each field with each field name

    add_filter('acf/validate_value/name=your-field-name', 'validate_text_as_number', 20, 4);
  • Missing ) on the line above should be if (preg_match('/[^0-9]/', $value)) {

  • post type == post
    current user == contributor

  • you can use the ACF JS API to get and update field values.

  • You have only specified the current user role. You also need to specify where you want the fields to appear. By only specifying the current role the group will appear anywhere that a field group can appear if the current user is of that role.

  • No, I have not seen anyone have success with making a bidirectional relationship field in a repeater work.

    In this case I would skip the bidirectional relationship and I would create a field for ingredients use only for making it easier to search. This field would just be a standard WP custom field with no need to be an ACF field that can be edited. It would not be editable from the ingredient side, only the recipe side. This would be a standard WP meta field that could hold multiple values.

    What I would do is I would create an acf/save_post action for recipes priority <10 so that it runs before ACF. I would loop through the repeater twice, once on the old values and once on the new values to collect a list of both old and new. Then compare and add/remove/update the meta key on for each ingredient.

    It would work very similar to a bidirectional field but instead getting the field to get the recipes on the ingredient side you would get the meta value and then use that value to query the recipes for each ingredient. Still not optimal, but better than a string of like queries.

  • WP only allows a single featured image per post, so you can’t add alternates.

  • You can use the field name or field key, the ID is not useful. Inside a repeater I would suggest using the field key, sometimes the field name does not work.

    Your issue was here


    to use the key is should be

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