Forum Replies Created

    if (is_admin()) {
      $field['readonly'] = true;
  • The first think you need to do us use the field key variant of the acf/update_value/ hook. The reason is that sub field, field names will be different.

    The second part will be the hard part. You need to get the field from the same row of the flex field as the field that you are filtering…. rather than try to explain

    add_filter('acf/update_value/key=field_604150e4d40c3', 'your_function_name', 20, 4);
    function your_function_name($value, $post_id, $field, $original) {
      $name = $field['name'];
      // $name will equal {FLEX FIELD NAME}_{INDEX}_{SUB FIELD NAME}
      // we need the the flex name and index
      // stip off this sub field name
      $name = str_replace('_this_field_name', '', $name);
      // append the other sub field name
      $name .= '_other_field_name';
      // use get_post_meta to get the value from the same row
      $other_value = get_post_meta($post_id, $name, true);
      // set value based on other value and return
      return $value;

    Also, I noticed that you are using a priority of 10, you should use a priority > 10 to ensure this happens after acf has saved the other value as well as making sure that the other field appears before this field when editing the page. Otherwise you may be getting the old value, or no value at all on a new post.

  • You create an acf/fields/post_object/query and you set $args['post_mime_type'] to an array of the allowed types. WP_Query Doc

  • You cannot do what you are attempting to do with only a server side action run when the post is saved.

    In addition it is the WP save_post action that triggers the acf/save_post action. If you insert or update a post in any way by using wp_insert_post() or wp_update_post() this will trigger will cause ACF to update fields if any ACF fields are submitted. ACF looks at $_POST['acf'] and if it contains anything it save the content to the post ID that was just added or updated. ACF is triggered by the save_post WP hook.

    Sorry, I am at a loss as how I can explain this further.

    Here is an example. Let’s say that I want to trigger a special message about the post being saved.

    In my functions.php file I would add something like

    add_action('acf/save_post', 'my_special_message_function', 20);
    function my_special_message_function($post_id) {
      // acf saved the post, set a flag in the DB
      update_post_meta($post_id, 'my_special_message_flag', 1);

    Then in my template that outputs the code where this message might appear I add

    $flag = get_post_meta($post->ID, 'my_special_message_flag', true);
    if ($flag == 1) {
       // show the special message
       echo 'The Post Was Saved';
       // unset the flag so it is not triggered again
       delete_post_meta($post->ID, 'my_special_message_flag');

    The same would be true if you want to determine what the output will be during the save action. The only difference would be that you would have to temporarily store all of the content that you want to be shown, and this would include the entire <script> tag if you wanted to add java script to the page.

  • There are no tools available that can be used to import options.

    There are several ways that you can work around this.

    The first is to use some type of custom post type instead of options.

    The second is that you can define a post ID to use for your options. This is complicated in a way. What you need to do is have a page or post of any kind. When creating the options page you set this posts ID as the post_id for the options page. Then you always import custom fields for the options of this post and you use this post ID instead of “options” when getting the options values from ACF.

    Overall, I would probably go with figuring out how to use a custom post type for this data rather than options.

  • You can do this using field keys, however, it still will not work the way you expect it to work without including the entire repeater. The reason is that ACF will not know when this field is submitted that you want to add a row to a repeater.

    To accomplish what you intend you will need to create a new field group that has the fields you want on the front end form. Then you will need to create an acf/save_post action that gets the values of these fields and adds a row to the repeater field.

  • When a post is set up WP does (or should) a single query to get and cache all of the postmeta fields for the post. These queries are based on the Post ID which is an indexed column in the DB. The number of queries should not be increased by the number of fields unless there is something else going on.

    Additional fields will increase the time it takes to do this one query but that time should not effect a single query more than a few milliseconds depending on what kind of content is being returned. It is possible, but it would be an extreme case. For an example of something that could effect performance here think about a page with 250 WYSIWYG fields with several paragraphs of content in every one of those fields. Let’s say that fields average of 1000 characters that equates to 250 X 1000 = 250,000 characters being returned by the DB and this can mean anywhere from 250K to almost 1MB of UTF8 data. Of course this is an exaggeration to make a point.

    There are things in ACF that will increase the number of queries, but this has to do with the formatting of the returned values. For example returning an array from image fields and galleries. Or returning post objects from relationship type fields.

  • 250+ fields sounds like there might be better ways to do what you want to do, but it would hard to be specific.

    But one example. You mention that you’re going to have “Featured Blog Posts”. I would not create a box for choosing what blog posts to show. I would create a field group for blog posts that had a true/false field to set each blog post as featured or not. Then I would add code to the template to show blog posts that were set to featured using some criteria like the most recent 3 or 5 posts or whatever. I would probably also modify the admin list of posts and add a column to show if each post is featured or not to make it easy for the client to find the ones that are featured and edit them to change it.

    As far as the rest goes, I would likely use Flexible Content for a lot of it and create layouts that meet the needs of their design. In fact, the “Featured Blog Posts” would likely be one of these layouts to let them choose some things about what “Featued Posts” to show. Or even, if the situation warranted, make it something that can be used for more than just featured posts, allowing them to adjust the content to suit their needs because with a little mortification it could be used for any realtionshp like “Related Posts”, “Related Pages”, etc.

  • Yes, acf/save_post is to allow you to do other things related to updating a field or a post. This can be anything that does not create “output” like changing meta data, sending information to a 3rd party API, altering the post in some way.

    If you want to update the meta data or the post then yes, you would use acf/save_post. But updating the post means that you are performing some action that alters the database. Altering the HTML output is not updating the database.

    Going back to your original code

    function my_acf_save_post($post_id) {
    add_action('acf/save_post', 'my_acf_save_post', 20);
    function console_log($output, $with_script_tags = true) {
      $js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) . ')';
      if($with_script_tags) {
        $js_code = '<script>' . $js_code . '</script>';
      echo $js_code;

    This is attempting to create HTML output during the saving of a post.
    Doing this requires 2 steps
    1) During the save process you store some data in some way
    2) During page display you retrieve that stored data and add it to the page

  • I have removed your topic from spam. I have no idea why this happens sometime.

  • You will need to do a custom query to get only posts with a custom field that has a specific value. I do not know enough about the rest api to know if you can filter the posts that are already being returned in the current end point or you need to create a custom end point.

  • @anna the help you are looking for is probably beyond what you will find here. You’re best resource is going to be from someone that has experience doing what you want to do with Elementor. There is documentation on their site for using ACF fields here You might also want to contact their support.

  • @boka003 creating an API to allow showing posts with specific field values is beyond the scope of help the you’re probably going to find on this forum.

    The limit of my knowledge is that you’re going to need to create a custom end point for the WP REST API. When this custom end point is called a query needs to be done to get and return the posts that you want to be shown.

  • The action function that you posted is not making any changes to fields. It is attempting to create output that is sent to the browser. Output is not created and sent to the browser during the update process. Trying to do so is likely creating causing errors.

  • The code you are trying to run happens when the post is saved, not when the edit page is being displayed. Sequence of actions
    1) Submit post
    2) Post data is saved
    3) Redirect to and reload post edit page
    You are attempting to output HTML during an operation that does not product output. I’m surprised that you are not getting PHP errors about headers already sent.

  • I am still not seeing this issue. As I said above, it is either a conflict or a corrupt JS file. See my previous comment. You could also try reinstalling WP and pluiins.

  • I know that a lot of the documentation for ACF still shows using the acf/load_field filter for changing fields. But almost all of the time an acf/prepare_field filter is the better choice. This is a newer hook that was added after most of the documentation was written.

    acf/load_field filters will be applied when exporting fields.

  • I can explain the issue you are having.

    ACF saves values on the save_post hook. ACF’s acf/save_post hooks runs at a priority of 10. What this means is that your action

    add_action('save_post', 'my_cpt_title_update', 10, 3);

    is running before acf has saved the values. You might think that this is working in the admin but what should be happening is that you’re updating the title with the old value of the field and not the new value if it’s being changed.

    It’s not working at all on the front end because there is not “old” value as it’s a new post. Your action is running before ACF has saved it.

    You can try increasing the priority of your action to something >10, but I’m not sure that will work.

  • I’m curious, because I have never seen this. I have another question.

    Do yu have any acf/load_field filters in place that effect image fields? And are these filters common for you?

    The reason I as is that acf/load_field filters can affect the fields during export and import. Or I should say that I have run into an issue with these filters interfering with exports/imports in the past.

  • Remove the quotes here

    echo wp_get_attachment_image($pics_contrib, 'full');
  • There is only one choice for field labels, to prefix them or not to prefix them and they are always shown as “Clone Label %field_label%”

    If you have other choices then you have some other modifications that are not part of ACF.

    To not prefix labels you just set it to “No”

  • Date fields are always stored in the DB in the format “Ymd”. The format returned when using get_field() is determined by the setting for return format.

    The default for the third parameter is true, meaning to format the value, as determined by the field settings. setting it to false returns the unformatted value as stored in the database.

    function my_cpt_title_update( $post_id, $post, $update ) {
    $title = array();
    if( get_post_type() == 'cpt' ) {
    $title = get_field('acf_variable', $post_id);
    $content = array(
    'ID' => $post_id,
    'post_title' => $title
    remove_action('acf/save_post','my_cpt_title_update', 20);
    wp_update_post( $content );
    add_filter('acf/save_post', 'my_cpt_title_update', 20);
     add_action('acf/save_post', 'my_cpt_title_update', 20);
  • Any existing field groups in the theme are either registered through PHP or they are in JSON files. If you ever plan to update the theme then I would highly recommend that you do not edit any of the theme’s files and instead create a child theme and then create new field groups to hold any additional fields that you want to create.

    For the admin you can simple add this to the child themes functions.php file in order to have the admin show without editing the theme files.

    add_filter('acf/settings/show_admin', 'my_new_acf_settings_show_admin', 20);
    function my_new_acf_settings_show_admin($show_admin) {
      return true;
  • The only way that you can alter the order of the terms in an ACF taxonomy field would be to use acf/fields/taxonomy/query and the sorting would need to be something you could apply to a term query using the order/orderby arguments.

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