And again, I solved it on my own ^^.
I ended up with simple input fields.
If anyone is interested in it, here is my admin.js code and a screencast gif:
(function($){
'use strict';
acf.add_action('append', function( $el ){
var layout = $el.attr('data-layout');
if( layout === null || typeof layout === 'undefined') return;
if( layout && layout.indexOf('_product') === -1 ) return;
var $productAttributes = acf.get_field('', jQuery('.values [data-name="product_attributes"]'));
var attributes = $productAttributes.find('textarea').val();
$.each( attributes.split(/\n/), function ( i, attr ) {
$el.find('a[data-event="add-row"]').last().trigger('click');
var name_input = $el.find('tr.acf-row:not(.acf-clone) [data-name="attribute_name"] input');
name_input.last().val(attr);
//name_input.prop('disabled', true); //not storing in db
});
});
})(jQuery);
This was not your question in previous comments.
Read the Documentation about Multilingual Custom Fields.
<?php
$field_name = "service_for";
$fields = get_field($field_name);
if($fields){
echo '<div class="col-xs-4 col-lg-3"><strong>Service for:</strong></div>';
echo '<div class="col-xs-8 col-lg-9">';
foreach ($fields as $field){
echo $field['value'] . ' ';
}
echo '</div>';
}
?>
Take a look at the documentation: https://www.advancedcustomfields.com/resources/checkbox/
This example works, if you selected “Both (Array)” in “Return Format” option
<?php
$field_name = "service_for";
$fields = get_field($field_name);
if($fields){
foreach ($fields as $field){
echo '<div class="col-xs-4 col-lg-3"><strong>' . $field['label'] . ':' . '</strong></div>';
echo '<div class="col-xs-8 col-lg-9">' . $field['value'] . '</div>';
}
}
?>
In meta_query
array you don´t need to use the prefix meta_
and I don´t know if it is necessary to use type
:
$eventi = get_posts(array(
'post_type' => 'eventi',
'posts_per_page' => -1,
'meta_key' => 'eve_start_date', //setting the meta_key which will be used to order
'orderby' => 'meta_value', //if the meta_key (population) is numeric use meta_value_num instead
'order' => 'ASC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'correla_evento_a_struttura', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
),
array(
'key' => 'eve_start_date',
'value' => date('Ymd'),
'compare' => '>='
),
),
));
You have to tell what kind of relation it is for multiple meta querys. Use it like this 'relation' => 'XXX',
(AND
, OR
…), in the meta_query
array.
And in your query it should look like this:
$eventi = get_posts( array(
'post_type' => 'eventi',
'posts_per_page' => - 1,
'meta_key' => 'eve_start_date', //setting the meta_key which will be used to order
'orderby' => 'meta_value', //if the meta_key (population) is numeric use meta_value_num instead
'order' => 'ASC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'correla_evento_a_struttura',
// name of custom field
'value' => '"' . get_the_ID() . '"',
// matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
),
array(
'key' => 'eve_start_date',
'type' => 'DATE',
// You can also try changing it to TIME or DATE if it doesn't work
'value' => date( "j F Y" ),
// deve coincidere con output usato x data -> http://www.korian.it/wp-admin/post.php?post=11522&action=edit
'compare' => '>='
),
),
) );
Hi,
this is a know problem in current WordPress Version 4.8.3.
Please see: https://support.advancedcustomfields.com/forums/topic/percentage-in-sql/
Pascal
The esc_url() function is included in the WP_Query Class. So if you do not use it by your own, it gets called in WP-Core. The behavoir is indeed that a single %
gets replaced by a hash like {47d84f1ee58a81956d53c64e8fafb5526c536eecab2be9c113fc33e7e9c86fba}
.
Try to replace %
with %d
. If it doesn´t help, then paste your hole code here.
[EDIT]
Okay this is a know problem with ACF repeater fields. There is a discussion about it (here) and also a new ticket. You can try the workaround (here).
The best way, is to use the command line interface for WordPress:
http://wp-cli.org/
Here are the options and arguments to use for search and replace:
https://developer.wordpress.org/cli/commands/search-replace/
For my custom field type I needed to get all values at once and the function update_value( $value, $post_id, $field )
only handles each field seperate. Because the Amazon Product Advertising API only allows
… an initial usage limit of 1 request per second*.
I had to find another way.
So after a while I realized, that the only way to get all fields at once on save, is to hook into acf/save_post
before it gets modified.
I have to place a seperate action hook into __constructor()
/ initialize()
:
add_action('acf/save_post', array($this, 'on_save_values'), 1);
and then iterate over all fields of acf:
function on_save_values( $post_id ) {
// bail early if no ACF data
if( empty($_POST['acf']) ) {
return;
}
// array of field values
$fields = $_POST['acf'];
foreach($fields as $layouts){
//...
}
Maybe this helps anyone facing similar problems.
Hi,
first there seems to be a wrong declaration of the vars in your code:
<?php
//vars
$event = get_field('events');
$event = get_field('address'); // should be $address ?
Then if you want to get the cloned fields, you simply call it by field name to get an array of subfields OR by using the prefix for each field (see your settings screenshot => you enabled this option):
$location = get_field('location');
<div id="address" itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
<strong>Address: </strong><span itemprop="streetAddress"><?php echo $location['street_address']; ?></span>, <span itemprop="addressLocality"> <?php echo $location['city']; ?></span>, <span itemprop="addressRegion"><?php echo $location['state']; ?></span>, <span itemprop="addressCountry"><?php echo $location['country']; ?></span>
</div>
Example for getting seperate subfields:
$location_street_address = get_field('location_street_address');
$location_city = get_field('location_city');
$location_state = get_field('location_state');
$location_country = get_field('location_country');
<div id="address" itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
<strong>Address: </strong><span itemprop="streetAddress"><?php echo $location_street_address; ?></span>, <span itemprop="addressLocality"> <?php echo $location_city; ?></span>, <span itemprop="addressRegion"><?php echo $location_state; ?></span>, <span itemprop="addressCountry"><?php echo $location_country; ?></span>
</div>
Are this percent symbols placeholder? If no and you do no more query preparation, then you should escape them with an extra percent symbol like the documentation says:
Literals (%) as parts of the query must be properly written as %%.
The last security update in WP 4.8.3 was a changed behaviour of esc_sql(). If you using it, here is a solution:
https://make.wordpress.org/core/2017/10/31/changed-behaviour-of-esc_sql-in-wordpress-4-8-3/
If your figures connected to taxonomies, then you can filter by tax_query
Your query has to look like this:
// filter on figures from serie's taxonomy
$args = array(
'post_type' => 'figure',
'posts_per_page' => -1,
'meta_key' => 'release_date_fr',
'orderby' => 'meta_value',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'serie', // taxonomy name
'field' => 'slug', // term_id, slug or name
'terms' => array( 'the-legend-of-zelda', 'hyrule-warriors' ), // single value or array of term id(s), term slug(s) or term name(s)
)
)
);
// query the figures
$the_query = new WP_Query($args);
BTW: If there is a error 500, then there is a new entry in you error logs, with more details about the error. Always start at this point to look for a solution.
Oh, did you see the missing ;
at the end of $date_fr = date("Y-m-d", $unixtimestamp)
? :D… sorry. If you´re working with Date Picker field, this should also works fine :).
You missplaced the span
opening tags before the questions if each field is present. Also there should always be one identical id at the current page, so change the parameter of the ids. (also change id="button"
to class="button"
)
<h1 style="font-size:18px; color:#1e238b;"> FEATURES</h1>
<?php if( get_field('dab_radio') ): ?>
<span id="one"><?php the_field('dab_radio') ?></span><div class="button">DAB Radio</div>
<?php endif ?>
<?php if( get_field('bluetooth') ): ?>
<span id="two"><?php the_field('bluetooth') ?></span><div class="button">bluetooth</div>
<?php endif ?>
<?php if( get_field('air_con') ): ?>
<span id="three"><?php the_field('air_con') ?></span><div class="button">Air conditioning</div>
<?php endif ?>
<?php if( get_field('sat_nav') ): ?>
<span id="four"><?php the_field('sat_nav') ?></span><div class="button">Sat Nav</div>
<?php endif ?>
<?php if( get_field('heated_seats') ): ?>
<span id="five"><?php the_field('heated_seats') ?></span><div class="button">Heated Seats</div>
<?php endif ?>
Did you changed the database creditials to the web hosting envoirement?
Otherwise write the error log in here (https://codex.wordpress.org/Debugging_in_WordPress).
change this:
$menu_navbar_sottotitolo = get_field('menu_navbar_sottotitolo', $item);
if( $icon ) {
$item->title .= '<br/><small>'.$menu_navbar_sottotitolo.'</small>';
}
to this:
$menu_navbar_sottotitolo = get_field('menu_navbar_sottotitolo', $item);
if( $menu_navbar_sottotitolo ) {
$item->title .= '<br/><small>'.$menu_navbar_sottotitolo.'</small>';
}
First: I am not familiar with acf_form(), but let´s go trough it.
Is this problem also present in other browsers?
IMHO it is related to a “bug” in jquery using .val()
on fields which are hidden on page load.
One workaround is to use $('#myInput').attr('value', value);
instead, but am I right with the assumption, that the JS comes from acf :D.
I have this little function to search through an object or array:
/**
* Search for a value in a multidimensional array or object
*
* @param $needle What to search for
* @param $haystack The array to search in
* @param bool $strict Strict mode
* @param $needle_field The field name to search in
* @return bool
*
* @author Pascal Jordin
*/
function search_recursive($needle, $haystack, $strict = false, $needle_field = false){
if ($needle_field) {
if (is_array($haystack)){
foreach ($haystack as $item) {
if (isset($item[$needle_field]) && ($strict ? $item[$needle_field] === $needle : $item[$needle_field] == $needle) || ((is_object($item) || is_array($item)) && search_recursive($needle, $item, $strict, $needle_field))) {
return true;
}
}
} elseif (is_object($haystack)){
foreach ($haystack as $item) {
if (isset($item->$needle_field) && ($strict ? $item->$needle_field === $needle : $item->$needle_field == $needle) || ((is_object($item) || is_array($item)) && search_recursive($needle, $item, $strict, $needle_field))) {
return true;
}
}
}
} else {
if (is_array($haystack) || is_object($haystack) || $haystack instanceof Traversable) {
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || ((is_object($item) || is_array($item)) && search_recursive($needle, $item, $strict, $needle_field))) {
return true;
}
}
}
}
return false;
}
With this you could search for it like:
$field = get_field('repeater_field_name');
$match = search_recursive('the phrase', $field, false, 'title');
Then $match
is true
if phrase match value of any sub field named title
.
Try one of these examples:
To get both field
and menu
<?php
$id = '' //(string) (required) Menu 'id','name' or 'slug'
$menu = wp_get_nav_menu_object( $id );
$field = get_field('field_name', $menu);
To get only the field
:
<?php
// WP < 4.4
$post_id = 'nav_menu_1' //the number must be the menu ID
// WP >= 4.4
$post_id = 'term_1' //the number must be the menu ID
$field = get_field('field_name', $post_id);
EDIT: Different calls for WP Versions
This should work:
<?php
$endOfDay = strtotime("tomorrow") - 1;
$unixtimestamp = strtotime(get_field('date_de_sortie_fr'));
$date_fr = date("Y-m-d", $unixtimestamp);
echo $unixtimestamp > $endOfDay ? "soon" : $date_fr;
EDITED: Syntax Error
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.