Figured it out. The publish-hook is to early for ACF, so none of the newly published fields are ready yet. I changed it up to this:
add_action( 'save_post', 'save_jobb', 100, 3 );
..also cranking up the priority to 100, to make sure that all other save jobs are done first.
Furthermore I added a check for post type early in the new function, since the new one takes on all posting in general:
$post_type = get_post_type($post_id);
if ( "jobb" != $post_type ) return;
Lastly, to prevent emails from being sent every time I edit a post belonging to a customer, I also added a small, new ACF field named mailsendt
– to just hold the value 0 or 1 depending on whether a mail already has been sent or not.
Hi @miked89
That is quite odd.
Kindly check the ensure that the field groups ID as the same.
If the issue is persistent, do open a support ticket as [email protected]
Cheers.
Hi @dawood
Thanks a lot for reaching out to us.
You would to have to use the standard WP query to query for posts which belong in that taxonomy.
Hope this helps.
Hi @cober
Thanks for reaching out to us.
You may consider using the post_not_in option in your query as follows .
'post__not_in' => array($post->ID)
Hope this helps.
Hi @amandahstd
Thanks for reaching out to us.
Unfortunately, that is quite tricky as it is not possible to link to several links using a single anchor.
You will need some custom solution or maybe using Jquery to trigger download for all the files on click.
Hope this helps.
Hi @uwe
Thanks for reaching out to us.
Unfortunately, there is currently no method to load all the sub_field values from a page using the plugins API.
You would to implement some custom to check if the item is a repeater field.
I’ll mark this as a feature request for the developer to take a look at when he has time.
Hi @gab1982 ,
That is quite odd as you are already providing the second parameter for the post ID in the loop.
Have you tried using option as in the documentation as opposed to options.
Kindly try it out and let me know how it goes.
Easiest way to achieve this is to update your post title using wp_update_post AFTER your acf_form() array – saves all the headache of creating a pre_save_post function and whatnot.
Example:
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
?>
<?php acf_form([
'post_id' => 'new_post',
'field_groups' => [19689],
'html_before_fields' => '<div id="formContainer">',
'html_after_fields' => '</div>',
'uploader' => 'basic',
'submit_value' => 'Submit',
'updated_message' => false,
'new_post' => array(
'post_type' => 'custompost',
'post_status' => 'publish',
)
]); ?>
<?php
//update post title using WP_Query, getting relevant post meta and passing it to the wp_update_post() function
$updatePost= new WP_Query([
'post_type' => 'custompost',
'post_status' => 'publish',
'author' => $current_user_id
]);
//loop
if($updatePost->have_posts()){
while($updatePost->have_posts()){
$updatePost->the_post();
$newTitle = get_post_meta(get_the_ID(),'field_name', true );
if($jobTitle){
wp_update_post([
'post_title' => $newTitle
]);
}
}
wp_reset_postdata();
}
?>
Sorry, sorry, long day, I read your question but blanked out.
ACF version is: 4.4.11
I just tested this on a basic WP site with nothing else installed. If I add this to the main editor in code view.
<div itemscope itemtype="http://schema.org/Review">
<meta itemprop="description" content="Skylight Alternative. Fill your home with the sun's free natural light." />
<meta itemprop="datePublished" content="2016-08-15" />
</div>
the switch to visual and then back to code view, the only thing that’s still there is
<div></div>
So I have to assume that you have something already installed that is modifying the main WP editor field.
This question actually comes up quite often.
ACF has never removed values that are no longer used and it has always been the case that we must implement our own logic to decide if we should get a field or not get a field. The same is true of conditional logic. Let’s say that you have a true false field and two fields based on if this field is checked or not. In your template you must check this field to see if it’s true or false because both of the fields might contain a value.
I your case, since sub pages will not have this menu field, the first thing you should be checking is if the page is a child of another page.
if ($post->parent != 0) {
// this is a child page.
}
The issue is a deep one, ACF does not know when saving a post, what fields are included and what fields are not. Really the point is that ACF does not know, and cannot figure out what fields exist that might need to be deleted or removed. There isn’t a way to get a list of all field and groups that ARE NOT included for a location. The only thing it has to go by is what is submitted and what fields ARE included for a location.
If it is necessary to make sure that values are removed when no longer needed then what we need to do is create an acf/save_post filter and do this checking ourselves and delete what we don’t want any more.
This is the same way the WP works. If you created your own custom fields not using ACF, then you removed the meta boxes from the admin interface for those fields all of that data would still exist in the database. If you use a particular theme that creates custom fields and then switch themes, more than likely any content in those custom fields will still exist if you decide to switch themes.
I looked at your original request and I’ve been looking for time to test things. You need to submit a new support ticket here https://support.advancedcustomfields.com/new-ticket/ It seems that ACF is not detecting template files for anything other than pages in child themes.
I actually like the 3rd solution from the post you linked to better, but I will probably do the change of the database as well, after making sure I don’t have any meta_keys > 191 characters though. Don’t know about anyone else, by I have a feeling that this effects more than that one query as indicated in the posts. Any time you use a db column in a WHERE or ORDERBY in a query, that field length not matching the key length is going to effect the query, contrary to what is said about it otherwise.
Anu,
The solution that we settled upon to speed up our post edit admin loading was to alter the postmeta meta_key index to 191. There are some potential downsides, but in our case it appears to be working for us. If you upgrade WP, check to make sure that the upgrade did not set meta_key back to 255. Here’s the mysql statement:
ALTER TABLE wp_postmeta MODIFY meta_key varchar(191);
Here’s an original thread that discusses the issue:
https://core.trac.wordpress.org/ticket/33885
Here’s a post that suggests some alternatives:
https://9seeds.com/wordpress-admin-post-editor-performance/
We also periodically run a query to delete empty rows both the hidden _ ACF field reference, for example: _some_field_name and the some_field_name field as well. ACF does not appear to mind if those are deleted and if you end up add a value to one of these fields, ACF will re-create the row/s. Here are the queries that I run to do the clean up. These queries work for us because all of the acf fields we want to delete start with the word “article”.
— delete “_article” postmeta rows that have corresponding empty “article” rows
DELETE wsp.*
FROM wp_postmeta AS wsp
WHERE meta_id IN (
SELECT mid
FROM (
SELECT t1.meta_id AS mid FROM wp_cdp_postmeta as t1
JOIN wp_cdp_postmeta as t2 ON t1.post_id = t2.post_id
WHERE t1.meta_key = CONCAT(‘_’,t2.meta_key)
AND t1.meta_key LIKE ‘_article_%’
AND (t2.meta_value = ” OR t2.meta_value = ‘0’)
AND t1.post_id BETWEEN 0 AND 400000
) x
);
— remove “AND t1.post_id BETWEEN 0 AND 400000” if you don’t want to limit the query
— delete empty “article” postmeta rows
DELETE FROM wp_postmeta WHERE meta_key LIKE ‘article%’ AND (meta_value = ” OR meta_value = ‘0’) AND post_id BETWEEN 0 AND 400000;
— remove “AND t1.post_id BETWEEN 0 AND 400000” if you don’t want to limit the query
— change DELETE to SELECT if you want to get a count before you run these statements. Always back up your database before your run a DELETE statement
@bosoxbill’s suggestion is what I would do. 2 select fields and a text/number field for the price. This will take custom jQuery as he indicates. I have some examples of custom code that gets values from fields and updates other fields, most of it uses AJAX, which you might need to get the price to set. https://github.com/Hube2/acf-dynamic-ajax-select-example
You’re also going to need a place in the admin for the client to set the actual prices for the different combinations. Basically, a field in the admin that is not available on the front end. Exactly how you’re going to do this I can’t say. The best solution would be that the client has a “Base Price” and that all of the other values are derived from some type of calculation based on this price. This part really depends on what the client needs and how they set the prices for the different options.
I have built a plugin, it does not fix the issue, but it does keep the admin from timing out/crashing and instead shows a “this is taking longer than expected” screen. https://github.com/Hube2/acf-prevent-timeouts
Recently I’ve been looking at the problem with searches using the standard WP search and the issue that content in custom fields is not searchable. In my case, the standard wp editor is not used at all so after the post is saved I copy all of the important ACF field values to post_content. As you can imagine, this put an even bigger load on saving a post and caused the site to crash. How I worked around this was to set a flag in options to tell me what posts need to be updated and then on the next admin page load an AJAX request is made that causes the copying to be done. The AJAX request uses a similar method to send a reply to the browser and then keep working, much like the method I use in the plugin I mentioned.
Here’s the problem with saving all of the values to one field in the database, ACF will not be able to find those fields or values later, nor will it update some of the values correctly, for example, adding other choices in radio and checkbox fields, updating taxonomies for a post, correctly formatting map field data, the list goes on. This is the reason that building something to bypass ACF and the individual saving of field values is so difficult. Not only to you need save the values in a faster way but you also need to do all of the field maintenance stuff that ACF does that most people don’t even know is going on. Saving everything to a single field is possible, but then when it comes time for displaying those values you would need to do all the work of getting and formatting the values for the fields values yourself.
This is definitely something that needs a solution for those of us that create large and complicated sites, but it’s something where the solution is going to be extremely complicated no matter how you decide to deal with it.
I think you’re going to need to use jQuery to run a script after the appropriate field has been selected. JQuery is JavaScript that you can use to manipulate values from the HTML.
If I understand you, you have two fields: one for the hotel and one for the bedrooms. So, run jQuery after the second field is selected and store the price in a third field. You can do the same thing on the back end or calculate when the post is saved.
I don’t think you need nine fields.
You could have one pulldown with the hotel level, another with the number of bedrooms and a third text field that gets updated with the price after saving. That would be a simple IF ELSE script.
Another option is to create one pulldown displaying and explaining the nine options, and setting the value of the option as the price. So what the person sees as is “Hotel level 1, 1 bedroom”, but the value of the choice is the price associated with that selection. This can be done when the ACF field is created.
Hope this helps. I’m not entirely sure if I am seeing what you are trying to do though.
Yeah, we’ve hit big performance issues in the edit screens using flexible content and repeaters for allowing clients to build their own layouts.
I wonder how easy it would be to add a setting to a field group “save as a single row”, which would save everything in that field group to 1 row. For most of our needs, we don’t need to query against the postmeta fields, so that would work fine and dramatically reduce the time spent in loading / updating pages in the back end
According to this site for $args to use https://www.billerickson.net/code/wp_query-arguments/
'meta_query' => array( //(array) - Custom field parameters (available with Version 3.1).
array(
'key' => 'color', //(string) - Custom field key.
'value' => 'blue', //(string/array) - Custom field value (Note: Array support is limited to a compare value of 'IN', 'NOT IN', 'BETWEEN', or 'NOT BETWEEN')
'type' => 'CHAR', //(string) - Custom field type. Possible values are 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'. Default value is 'CHAR'.
'compare' => '=', //(string) - Operator to test. Possible values are '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. Default value is '='.
),
array(
'key' => 'price',
'value' => array( 1,200 ),
'compare' => 'NOT LIKE'
)
So following the above example I would maybe try something like this and add as many keys as you need to in order to search all the taxonomies you want.
$args['meta_query'] = array(
array(
'key' => my_key_1,
'value' => $args['s'],
'compare' => 'LIKE',
),
array(
'key' => my_key_2,
'value' => $args['s'],
'compare' => 'LIKE',
),
array(
'key' => my_key_3,
'value' => $args['s'],
'compare' => 'LIKE',
)
);
return $args;
I did a test and the only way I could get ACF4 to not validate fields set as required was to turn off JavaScript on the test site. This means that for some reason the JS is not running, or maybe not even being loaded, or that there is a JS error stopping it from working.
Have you tried deactivating your other plugins or switching themes to see if anything might be interfering with ACF?
Dear John,
thank you very much. I moved acf_form_head()
before get_header()
.
But map still doen’t work. Do you have any idea please?
Than you very much!
<?php acf_form_head(); ?>
<?php
/*
Template Name: Add Page Template
*/
get_header();
?>
<div id="content">
<div class="container">
<div class="row">
<div class="col-sm-12">
<?php get_the_title(); ?>
<?php
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', 'page' );
endwhile; // End of the loop.
?>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12">
<?php
acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'new_post' => array(
'post_type' => 'place',
'post_status' => 'draft'
)
));
?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
Thanks so much @hube2 that did the trick.
Here’s what the final code ended up looking like:
<?php if (have_rows('folio_items')) {
while( have_rows('folio_items')) {
the_row();
if (get_sub_field('toggle_display')) { ?>
<!-- FOLIO ITEM FLEXIBLE CONTENT -->
<div class="col-md-3 col-sm-4 col-xs-6">
<a class="overlay" data-toggle="modal" data-target="#<?php the_sub_field('project_id'); ?>"><i class="fa fa-search-plus"></i><h3><?php the_sub_field('project_title'); ?></h3></a>
<img class="img-responsive" src="<?php the_sub_field('project_thumbnail'); ?>" alt="<?php the_sub_field('project_title'); ?> Thumbnail">
</div>
<div class="modal fade" id="<?php the_sub_field('project_id'); ?>" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"><?php the_sub_field('project_title'); ?></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-9 col-sm-8">
<?php the_sub_field('project_content'); ?>
</div>
<div class="col-md-3 col-sm-4">
<h5>Client</h5>
<p><?php the_sub_field('client_name'); ?></p>
<hr>
<h5>Details</h5>
<?php the_sub_field('project_details'); ?>
</div>
</div>
</div>
<div class="modal-footer">
<a href="#" data-dismiss="modal">Close Window <i class="fa fa-times"></i></a>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php } ?>
<?php } ?>
<?php } ?>
Very good question. I just did a quick test and it seems to be working as expected. Other things that can cause this include incompatibility with other plugins and/or something in the theme.
Most probably it has something to do with a JavaScript error or a PHP error during the AJAX request that does the validation. First thing to do is look in console and see if any JS errors are reported on the page. Next thing is to enable debugging and error logging and look in your error log to see if there are any PHP errors that could be causing the AJAX request to fail. https://codex.wordpress.org/WP_DEBUG
the_field("image_artiste")
echos the value of the field '['url']
has no meaning here since the value is not returned. Try echo get_field("image_artiste")["url"];
but I’m not sure this will work or the following which will always work.
$image = get_field("image_artiste");
echo $image['url'];
I didn’t reply sooner, I had thought to try this out, but I haven’t had time. It’s a lot of building to do to test a theory. I certain that it can be done though. When I was building the add on that I built, well, I just tried it and played with it until I got it to work. I had a specific need for a client, so I had the time. Frankly, if it had not worked I’m not sure what I would have done.
The ACF field type template https://github.com/elliotcondon/acf-field-type-template includes several methods that are commented out, load_value()
, update_value()
, render_field()
and format_value()
are the important ones.
I’m guessing that you want a real “value” + you want to add these additional settings.
In update_value
, you would need to look in the ‘$_POSTarray to get the values from the repeater field and then do something with the actual value of the field and these extra settings to store them in an array before they are saved to the database. The big question here is what does the submitted value look like? Which ties into the comment below about
render_field`
In ‘load_valuewhat you'd need to do is to extract the actual value from the field and then store your additional settings into some custom field argument, for example
$field[‘custom_settings’]`.
In render_field
, this is the part that’s a guess, but you should be able to set up a repeater field simply by calling one of the build in ACF functions that does this, possibly acf_render_field_wrap()
or acf_render_field()
or maybe even running the action do_action('acf/render_field', $repeater)
Then you have format_value
that would do the work of taking the “value” and applying your custom options from the repeater to it.
The question is, how much time do you have and how much time and frustration will is save the person that needs to use it. Only you can answer the question. In my case I had to give the client a way to add formatting to single lines of input that would be used for headings throughout the site and this also included the ability to apply specific colors to specific portions of the text. My choices were to build a field type or to implement some type of “markdown” in text fields or textarea fields. If I had gone the markdown path what would have happened is that the client would not have been able to manage this content themselves and I would have ended up doing the work anyway. So not only does the field type I created make it possible for the client to easily do the work themselves, it saves me a boatload of time that I would have been spending managing their content, far more time than it took me to create the field type. This is what I weighed the time to create the field type against, how much time will it save me later.
I can tell you one thing though. I will be keeping this conversation in mind on future projects. I find the possibility of doing something like this extremely interesting, as if you probably can’t tell that by this extensive comment :P. I will also probably investigate this if I ever manage to find some free time even if I don’t find a specific need.
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.