Yes, you should be able to just switch to the main blog before getting the field https://codex.wordpress.org/Function_Reference/switch_to_blog
In your search results page
$excerpt = get_the_excerpt();
if (!$excerpt) {
$excerpt = get_field('your-excerpt-field');
}
of add a “get_the_excerpt” filter in functions.php that does something similar https://codex.wordpress.org/Plugin_API/Filter_Reference/get_the_excerpt
I have an example for doing something similar using a true/false field, not sure if it will help you or not. https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/unique-repeater-checkbox
k, now that I’m looking back at this, you want to do a date query on post dates based on your values.
Sorry, ignore my last comment. What you need to do is format the date returned by ACF to a full MySQL date. You return format from ACF should be “Y-m-d”.
I’m not 100% sure that will work because post dates are stored as “Y-m-d H:i:s”, so you’ll need to test, but I can’t think of any reason that the query would not work without the time.
The reason that you need to open the post and save it is because that field_key is not added correctly to the database. When a new post is created the custom ACF field does not exist and this means that acf does not know exactly what to do with the field. This is why you need to use the field key when updating the field so that ACF knows that this is a date field and also inserts the correct field key reference into the database.
You should submit you request by opening a new support ticket https://support.advancedcustomfields.com/new-ticket/. It’s the best way to get this to the developer.
Can you post the code you’re using to do this
I am loading values to the Selecy field “report_involved_family” depending on other fields.
First problem is that the format you’re attempting to store is incorrect. ACF may display and return values in the format you set but it always stores date fields in the format “YYYYMMDD”
The second problem could be related to the adding a new post where the custom field does not exist yet or updating and existing post that already has a date value. When using update_field() for new post you always need to use the field key and not the field name.
What version of ACF are you using?
Whenever you use WP_Query to do a custom query you always need to call wp_reset_postdata() to reset WP back to the main query. Sometimes you need to call wp_reset_query(). If you don’t reset WP then it’s looking at the wrong query when it tries to display the list of posts on the admin page.
Not sure if you’ve figured out your problem or not. If you haven’t can you try to explain a little more about what the problem is?
How are you inserting the date into the database? Are you using update_field() or another method? What is the date format of the date that you’re inserting into the database?
ACF does not store dates in the database in the correct format for using a date query. The format ACF uses for date fields is “YYYYMMDD”. You need to use a meta query, the value can be searching using “BETWEEN” as either “NUMERIC” or “CHAR” types.
90% of the time when this happens it is due to a conflict with something. It could be a another plugin in something in your theme. More often then not it has been a pre_get_posts filter that is interfering with the acf queries.
You need to try to narrow down what it is by deactivating plugins and maybe switching themes.
If you do a search in this forum for “image field returns id instead of array” the topics that come up may help you.
For something like this you should open a new support ticket here https://support.advancedcustomfields.com/forums/topic/new-param-in-acfprepare_fields_for_import-filter/
Put the code where you are getting the value from acf, or just incorporate it into the call like I did above
$date = date('F j, Y H:ia', strtotime(get_field('date_field'));
echo $date;
I’m not seeing this issue on my testing site. Have you tried disabling other plugins or switching themes to see if something else is causing the issue?
If all of the data for each field is somehow in the wysiwyg field in some way that it can be axtracted, for example the data for one field is always in a p element with a specific class, and the same of everything else so that it can be reliably extracted, then using something like regular expressions may do it. It would still take a lot of testing and patience. It’s also not something you could run through a browser, it’s something you’d have to set up to run as crons and more than likely you’d have to do it in several passes.
What kind of fields are you trying to populate with data from the content?
Maybe possible if your moving content to a wysiwyg field, but if you’re splitting up your content into multiple fields then the only way to do it will be the hard way.
I just did a test with WP 4.7.2 and ACF 4.1.11 and everything is working for me.
try disabling plugins, using an unmodified 20xx theme. See if there’s a conflict. If that does not help try reinstalling WP and ACF.
the order by needs to be in the main query args and not in your meta query, along with anything else that is not part of the meta_query.
query_posts(array(
'orderby' => 'rand',
'showposts' => 1
'meta_query' => array(
array(
'key' => 'post_in_home_gallery',
'compare' => '==',
'value' => '1',
)
)
));
To do this you’re going to have to do a new WP_Query on these meta values. Something like this.
$district = get_field('district');
$price = get_field('price');
$low = $price-50;
$high = $price+50
$args = array(
'post_type' => 'your-post-type',
'post_per_page' => 3,
'meta_query' => array(
array(
'key' => 'district',
'value' => $district
),
array(
'key' => 'price',
'value' => $low,
'compare' => '>='
'type' => 'NUMERIC'
),
array(
'key' => 'price',
'value' => $high,
'compare' => '<='
'type' => 'NUMERIC'
)
)
);
$query = new WP_Query($args);
see https://codex.wordpress.org/Class_Reference/WP_Query
also https://www.advancedcustomfields.com/resources/query-posts-custom-fields/
The first time that you call the_field(), all of the custom field data for the post should be retrieved from the database and stored in the WP cache. Subsequent calls the the_field() get values from this cache. At least that’s the way it’s supposed to work.
You can test this by installing this plugin https://wordpress.org/plugins/query-monitor/
load your page and see how many queries are done. Then add this directly before your calls the_field();
$meta = get_post_meta();
This specifically tells WP to get all custom fields for a post. When you load your page again there should be no difference in the number of queries.
There isn’t any documentation on doing this. The best that I can offer is some examples I’ve created https://github.com/Hube2/acf-dynamic-ajax-select-example
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.