Here’s an old topic that the developer commented on https://support.advancedcustomfields.com/forums/topic/order-custom-post-by-sub-custom-field-values/ which basically says the same thing but points out that you could do this if you only looked at the first row of the repeater when sorting.
acf_get_setting('google_api_key');
should return the value
Using standard WP methods you would need to do a query for every post that might have a review and then loop through the repeater fields on every post to collect them all. If there are a lot this would more than likely time out your site, although you could probably incorporate some type of object or fragment caching. If you do a search you’ll find plenty of information on it.
You could use #wpdb and query the wp_meta table directly to speed things up https://codex.wordpress.org/Class_Reference/wpdb, but because you’re using repeater fields the query would be quite complicated. If you’re thinking about this you should probably spend some time digging around in the database to see how ACF stores the values of a repeater.
There are some premium search plugins that will solve the 1st problem. One of them can be found here https://facetwp.com/, there are others. It needs to be a search tool that will work with ACF and there aren’t that many of them.
There is nothing that I am aware of that will search related content. That is search the content of a related post in a relationship field and consider it to be part of the post that’s being shown. If you do find a solution for this that works without needing to manipulate data in some way, please let me know.
What I do for searching related content is that I build filters and actions that add the related content to hidden meta fields in the post. So, basically, all the content from all of the related posts is duplicated in the posts that are searched so that it can all be searched at once. I’ve even created a plugin that will do this integration. The main problem with this is all the extra content and custom fields that are required to make it work. https://github.com/Hube2/custom-field-converter
No, it isn’t, not without building your own shortcode functions, or doing what you’re doing. Even with what you’re doing, it won’t work with anything but text based fields.
If you look you will find many topics started here about the same subject, sorting posts by the values in repeater fields. The short and ugly answer is that this cannot be done.
The values in each repeater row are saved with a unique meta key. For example, let’s say that you have a repeater with a text sub field and you put values into three rows, the meta keys of the values are repeater_0_text
, repeater_1_text
, and repeater_2_text
. There isn’t any logical way using SQL to create a query that will sort results based on this setup.
I’ve found that repeaters should only be used for data that will be displayed without alteration and that a repeater should never be used when the data in them will be needed for complex operations, like sorting posts.
I you must sort posts by these values then you will need to get creative and go beyond what ACF can do for you. We could, for example, easily sort posts by a repeater sub field if the values in that field were stored in the standard WP way for storing multiple values for a single meta_key and using an acf/save_post filter is is possible to get the values from a repeater and then store them properly. Here is an example. Please note, it is an example, it does not include all the necessary code and it may contain errors, I’m not testing this.
// add an action that will run after acf is done
add_action('acf/save_post', 'my_save_post_action', 20);
function my_save_post_action($post_id) {
// make sure the post is one we want to update
if (get_post_type($post_id) != 'my-post-type') {
return;
}
// set up a new meta key
// that will hold the repeater sub field
// in standard WP fashion
// the meta key needs to be unique
$meta_key = 'repeater_text_copy';
// delete all the data form our meta key
delete_post_meta($post_id, $meta_key);
// now get the values from the repeater and
// store in the new location
if (have_rows('repeater', $post_id)) {
while(have_rows('repeater', $post_id)) {
the_row();
// insert the post meta with $unique parameter set to false
add_post_meta($post_id, $meta_key, get_sub_field('text'), false);
}
}
}
Now you can query posts and sort them based on the value in this new meta field.
The last section of this page gives a basic explanation of how to use $_GET parameters https://www.advancedcustomfields.com/resources/query-posts-custom-fields/. I’d suggest you start there. You will need to have some logic in you template that displays different content based on what’s being shown. As for navigation, you’d probably need to build that yourself, generate the correct links and add them to the page based on your own queries.
Importing, or updating a field group or changing a field will have no effect on any data that is saved to those fields on posts, or wherever they are saved. That data will still be there. If you have changed a fields properties then the values in those fields may or may not continue to work depending on the changes that were made.
It’s hard to say what will continue to work and what won’t, it really depends on what the field is, how the value is stored and what is done with the value for display.
The ACF sortcode only works with simple text fields and will not work with complex fields like flex fields https://www.advancedcustomfields.com/resources/shortcode/. If you want to be able to use shortcodes for more complex fields then you’ll need to code the shortcode functions yourself. https://codex.wordpress.org/Shortcode_API
you can use update_field() to set the value. Pass an array for the values
array(
// nested array for each row
array(
// element for each field
'field_409832048038' => 'value',
'field_04230949393a' => 'value',
// etc
)
)
I show field keys because it’s better to use field keys when updating fields that may not have values yet.
You may want to start a new topic for your question. Old topics don’t get much attention accept for those that have posted in them. You might get some fresh eyes on this with a new thread.
I was just reading the documentation before. I checked the code and wp_check_post_lock
is a function, so I don’t know why the error. To be honest, the documentation on the whole post locking thing is not very clear. For example, there’s nothing that I can find to unlock a post, only to lock it. The poor documentation on the subject may be the reason that it’s not something ACF is doing.
You are trying to run PHP code but echoed code is not run.
I would suggest altering your input to just include the second part of the shortcode, for example you would enter scales.svg
into the field.
Then in your template you would do
<?php get_teplate_part('svg/inline', get_field('icon_field')); ?>
This is something I have not seen come up before, but probably a good question. Because ACF will not know how a particular site needs to work I don’t think you see it added. But this is something you can manage yourself. Before calling ACF form test to see if the post is locked https://codex.wordpress.org/Function_Reference/wp_check_post_lock, if it is then do not call acf_form() and show your own message about the post being locked. You can also lock https://codex.wordpress.org/Function_Reference/wp_set_post_lock and unlock the page. I’m sure there’s more to it.
But no this is not something that ACF does and I cannot recall it coming as a topic here before. You might want to submit the feature request in a new ticket https://support.advancedcustomfields.com/new-ticket/
It wasn’t a mistake. The other topic turns out to be a bug in syncing field groups with clone fields. Your problem happens when you sync a field groups with clone fields. The issues are related in some way and I have reported the fact that there is an issue with syncing field groups that have clone fields to the developer.
Not easily. You could move the field group to a file or php, figure out how to know which post is being loaded when you would normally add local field groups, then see if that post has any values and only add the local field group if it does. I’m sure it’s possible, but I can’t tell you exactly how without building it.
An update on this, there is a fix coming that will also be tied into this issue https://support.advancedcustomfields.com/forums/topic/acf_form-security-issues/. I see a new class that will be automatically instantiated. acf_form() and acf_form_head() will be wrappers for methods in this class.
I’m not 100% sure what going to be done about the security issue, I’d keep an eye on that thread.
I think that this topic is related to this one https://support.advancedcustomfields.com/forums/topic/fetching-value-from-cloned-field-in-acfload_field-filter/ and I have reported the sync issue with clone fields to the developer.
I took seeing the video for me to understand and for it to sink (no pun intended) in that this is a field syncing issue, and not an importing issue. I have reported this topic to the developer.
There isn’t a lot of documentation or useful examples of doing what you want. I have created an example of how to do something similar to this, my example draws it’s information from post types, but it can be changed to other sources of information. The important part of the example is the JS code that gets the value from one field when it’s changed and hooks into the ACF ajax code to get the results to populate another select field with. Hope it helps https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-select-example
I have not used the rest api with acf, but generally, in templates, I do something like
$value = get_field('field-name');
if (!$value) {
$value = 'default value';
}
Since I’m assuming that you’re building code in javascript to use the rest api, you’ll need to alter this to check whatever field your looking for in what the api returns.
Like I said, the people that put together the acf to rest plugin will likely be able to answer you’re questions better than anyone.
Nice link Jonathan, I haven’t seen that before. That will be a whole lot easier than constantly copying the fields from the theme folder to my plugin folder every time I make a change.
Actually, when you start a new topic here https://support.advancedcustomfields.com/new-topic/, at the top of the page it clearly says
Please note that forum topics are no longer used as support tickets. Instead, please open a support ticket
The fastest way to get a bug report to the developer is by starting a support ticket. This forum is a user support forum where users help other users. Yes, at one time the developer used this forum for all communication, but that is no longer the case. The developer does not read these forums on a regular bases, if he did then he’d never get any work done on ACF.
Some of the people that help here can bring things to the developer’s attention, but before I will do that I need to be convinced that it is a bug and not that something is being used wrong and so far you have not convinced me of this. Mostly because I’ve done what you’re trying to do without any trouble.
The only way to do this currently is to use an acf/load_field filter and to set either the readonly
or disabled
property to true or 1, and this won’t work with all field types, it won’t work on the fields that use Select2. There currently isn’t a way to hide a fields except to add css to the admin_head to hide the field containers.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.