remove the “echo”. Not required, but you should also add some checking and set a default value:
$email_to = '[email protected]';
$contact_form_email = get_field(‘contact_form_email’,'options’);
if ($contact_form_email) {
$email_to = $contact_form_email;
}
$email_subject = “Submission from Website”;
alright i needed nearly an hour to find the solution but here is it:
new WP_Query( array (
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'nutzer',
'value' => '"'.$user_ID.'"',
'compare' => 'LIKE'
)
)
));
If you need to apply different sizes to an image added with ACF the I’ve found the best choice is to have it return the attachment id rather than any of the other things it can return. Then it is simple to us a different images sizes of the same image.
$attachment_id = get_field('taximage', 'industrygroups_'.$lc->term_id);
if ($attachment_id) {
$image = wp_get_attachment_image_src($attachment_id, 'my-custom-size');
if ($image) {
?><img class="img-responsive img-thumbnail" src="<?php echo $image[0]; ?>" /><?php
} // end if image
} // end if attachment_id
Obviously a long time since this was posted but I’ve had the same problem quite a lot, especially when it comes to icons for elements and making them editable by the client and using SVG.
I decided to have a crack at a solution. It’s not pretty but it works after the first time the SVG has been uploaded/chosen.
Stick in your functions.php;
function unleash_enqueue_scripts( $hook ) {
if( !in_array( $hook, array( 'post.php', 'post-new.php' ) ) )
return;
wp_enqueue_script(
'resizeSvg', // Handle
'/path/to/theme/js/resizeSVG.js', // Path to file
array( 'jquery' )
);
}
add_action( 'admin_enqueue_scripts', 'unleash_enqueue_scripts', 2000 );
Then create a file in your JS folder called resizeSVG.js and add in the following;
jQuery(document).ready(function() {
jQuery('.acf-image-image').each(function(){
if(jQuery(this).attr('src').indexOf('.svg') > 0) {
jQuery(this).css('width', '128px');
}
});
});
This basically resizes any acf-image that has .svg in it down to 128px, obviously you can change that as needed.
<p>Despite ポールスミスバッグアウトレット its obvious link to Thirties era wartime motorcycles from BMW, the 2009 Ural T sidecar motorcycle can’t really be described as "retro." CHICAGO, April 25, 2014 /PRNewswire iReach/ There is ポール スミス 財布 メンズ a lot of excitement in the country surrounding the all new 2015 Porsche Macan crossover SUV since it was announced from the German automaker just a few short months ago."Nothing ポールスミスバッグ could have prepared me for the things that I witnessed. As I became more aware of the state of health care, I realized these experiences weren’t just happening ポール スミス 財布 to me and my loved ones it seemed everyone I met in the hallways and rooms of Eastern Health facilities, wherever I went, had a horror story to tell. http://www.anakinssong.com/paul/</p>
Hube2,
The JS trigger I am asking about is acf/setup_fields. This is triggered when ACF fields are added to a wordpress post/page. And re-triggered every time new fields are added such as in a repeater.
The post you linked to is talking about issues with a different action (the php action acf/register_fields which used to be used in v4 when adding new field types).
Unless I am missing something, the pages you linked to are not related to my question (although I do appreciate your effort to help). Please correct me if I am wrong and I am missing something.
Thanks,
Matt Keys
Update. My bad about the strpos() !== -1. Instead, those should be strpos() !== FALSE. Also, I was finding errors on some other jQuery-heavy admin pages, so I added a javascript check for the ‘.acf-color_picker’ element. Here’s my revised code:
function load_javascript_on_admin_edit_post_page() {
global $parent_file;
// If we're on the edit post page.
if (
strpos($parent_file, 'post-new.php') !== FALSE ||
strpos($parent_file, 'edit.php') !== FALSE ||
strpos($parent_file, 'post.php') !== FALSE
) {
echo "
<script>
jQuery(document).ready(function($){
if ($('.acf-color_picker').length) {
$('.acf-color_picker').iris({
palettes: ['#e40571', '#4b63a4', '#ffcb05', '#fff', '#000'],
change: function(event, ui){
$(this).parents('.wp-picker-container').find('.wp-color-result').css('background-color', ui.color.toString());
}
});
}
});
</script>
";
}
}
add_action('in_admin_footer', 'load_javascript_on_admin_edit_post_page');
Solved it with this:
<?php if(get_field('faqs')): while(has_sub_field('faqs')):
$variable = get_sub_field('category');
if(get_sub_field('qa')): while(has_sub_field('qa')): ?>
<article class="envor-sorting-item <?php echo $variable; ?>">
<header><?php the_sub_field('question'); ?> <i class="fa fa-plus"></i></header>
<?php the_sub_field('answer'); ?>
</article>
<?php endwhile; endif;
endwhile; endif; ?>
Not sure what I was doing wrong before!! Hopefully it helps someone else
Link to question and answer: http://support.advancedcustomfields.com/forums/topic/acfregister_fields-hook-missing/
There is a reference about other changes: http://www.advancedcustomfields.com/resources/updates/whats-new-version-5/
Hi Elliot, no worries at all. Actually i’ve figured out the root of the problem. It wasn’t a temporary glitch, the defined urls for WP_HOME and WP_SITEURL were the reason.
I am developing locally with MAMP and Codekit 2. When i’ve used e.g. those settings:
define('WP_HOME', 'http://192.168.0.198:8888/mysite');
define('WP_SITEURL', 'http://192.168.0.198:8888/mysite');
even when i’ve set portforwarding for this ip and port i was unable to access the developed site from remote. But a friend suggested me the following:
define('WP_HOME', 'http://'.$_SERVER["HTTP_HOST"].'/mysite');
define('WP_SITEURL', 'http://'.$_SERVER["HTTP_HOST"].'/mysite');
With those definitions i was able that someone else could access my locally developed site from remote. I think since i’ve changed to those $_SERVER["HTTP_HOST"]
definitions other updates worked fine but it was the first update with ACF. Now i know the cause but the why i am not sure. 😉 But maybe that helps you to understand my discovered issue better. Should the update basically work with $_SERVER["HTTP_HOST"]
or not all and i shall return using local ips? Best regards Ralf
nice one elliot! this leads me to the right direction. but i think i found a bug?! i am using ACF 5.0.3.
this is my function:
/* auto populate acf field with comment IDs */
function my_acf_load_field( $field ){
$assignedpost = get_field('produktblog');
$comments = get_comments(array(
'status' => 'approve',
'post_id' => $assignedpost->ID
));
if( is_array($comments) )
{
foreach( $comments as $key=>$comment )
{
$field['choices'][ $key ] = $comment->comment_content;
$field['default_value'][ $key ] = $comment->comment_ID;
}
}
return $field;
}
// v4.0.0 and above
add_filter('acf/load_field/name=kommentare', 'my_acf_load_field');
and this is the print_r from $field:
Array
(
[ID] => 150
[key] => field_53e327ee805e6
[label] => Kommentare
[name] => kommentare
[prefix] =>
[type] => select
[value] =>
[menu_order] => 0
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 6
[_name] => kommentare
[_input] =>
[_valid] => 1
[choices] => Array
(
[0] => kommentar3
[1] => kommentar2
[2] => kommentar1
)
[default_value] => Array
(
[0] => 7
[1] => 6
[2] => 5
)
[allow_null] => 1
[multiple] => 1
[ui] => 0
[ajax] => 0
[placeholder] =>
[disabled] => 0
[readonly] => 0
)
the select field accepts the choices but not the values:
https://www.dropbox.com/s/h4ek9agt4wk97vg/Screenshot%202014-08-07%2009.47.48.png
so as you can see, the value is still 0,1,2. but it has to be 7,6,5
That was the problem indeed, it turns out. The ID of the field was changed, I think, when I upgraded.
Still trying to figure out why the new_post isn’t working in this installation. I’m using the exact code on both sites for creating a new post, but no luck on later one. I’m guessing it’s something I haven’t found in my own work though, so I’ll keep looking. Thanks Elliot!
$newapp = array (
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'appointment',
'post_status' => 'publish',
'post_title' => 'tempslug',
),
'field_groups' => array('414'),
'form_attributes' => array (
'id' => 'new-app-form',
),
'submit_value' => 'Post Appointment',
'update_message' => false,
'return' => add_query_arg(array('adminTab'=>'apps', 'sub-tab'=>'available', 'appcreated'=>true), get_the_permalink()),
);
acf_form($newapp);
Hi @nicmare
Thanks for the question. At the moment, there are no fields which you can use to select comments on a post.
I believe it will be possible to use a multi-select field, and use the following tutorial to customize the available choices.
http://www.advancedcustomfields.com/resources/tutorials/dynamically-populate-a-select-fields-choices/
You will need to find some code to query and return the comment ID’s as the select field’s choices
Cheers
E
Hi @Jan
Thanks for the question. Currently no, but I will add in a field setting to disable the html tab.
Cheers
E
Hi @rywn
No worries. Just let them know of the thread here and that there is a conflict between relevanssi and ACF PRO on the relaitonship field which uses get_posts during an AJAX request.
Also let them know of the PHP errors you attached above as these point to code within the relevanssi plugin.
I’m not sure why the issue is occuring, but hopefully they can point us in the right direction
Cheers
E
I got a similar question, I wanna take some premium addons and want to know if there’s a discount or something for purchase all of them.
I’m trying this with version 5, and I had to adjust this a little — to change the jQuery selector from ‘.color_picker’ to ‘.acf-color_picker’. Here’s my code:
function load_javascript_on_admin_edit_post_page() {
global $parent_file;
// If we're on the edit post page.
if (
strpos($parent_file, 'post-new.php') !== -1 ||
strpos($parent_file, 'edit.php') !== -1 ||
strpos($parent_file, 'post.php') !== -1
) {
echo "
<script>
jQuery(document).ready(function(){
jQuery('.acf-color_picker').iris({
palettes: ['#e40571', '#4b63a4', '#ffcb05', '#fff', '#000'],
change: function(event, ui){
jQuery(this).parents('.wp-picker-container').find('.wp-color-result').css('background-color', ui.color.toString());
}
});
});
</script>
";
}
}
add_action('in_admin_footer', 'load_javascript_on_admin_edit_post_page');
Paid to get the answer from somewhere else. Here it is for anyone wanting to do this: basically, if your ACF check box field is called “services_offered” and one of the services was “ac” then it would look like this:
<?php
$values = get_field('services_offered');
if(in_array("ac", $values )){
?>
<div class="dealer-services-icon"><img src="<?php echo get_bloginfo('url'); ?>/media/icon-ac.png" alt="<?php the_field('focus_city'); ?> Air Conditioning Service" class="tooltips" title="Air Conditioning"></div>
<?
}
?>
I solved it, I just had to add a counter in the array( value[“here”] ), so that if, lets say, I wanna modify the information of the 1st row, then id put something like this:
$counter = 0;
$value[$counter] = array("fecha" => $fech4,
"saldo" => $sal14,
"inversion_en_el_periodo" => $ielp4,
"interes_causado_en_el_periodo" => $icelp4,
"cantidad_pagada" => $cp4,
"cantidad_reinvertida" => $cr,
"saldo_final" => $sf4,);
update_field( $field_key, $value, $post_id );
$counter=$counter+1;
and then keep looping it around
Nevermind, I got it resolved. For reference, anywhere I declared $queried_object
I replaced with $taxonomy . '_' . $term_id
For example:
<?php if( get_field('header_image_cat', $queried_object) ) { ?>
should read:
<?php if( get_field('header_image_cat', $taxonomy . '_' . $term_id) ) { ?>
Ok so I’ve managed to isolate the problem to a categories field in my fron end form (the user gets to choose which category the post should go into). If the user leaves it as ‘none'(null) there are no errors but if a category is chosen the submitting errors above are displayed. I can’t test this for editing the post because I’m also having this issue: http://support.advancedcustomfields.com/forums/topic/when-selecting-taxonomy-acf-fields-disappear/#post-15118
I’ve added a bit more info on the code I’m using below as I’m probably doing something wrong…
Would greatly appreciate any help with this
my form for submiting:
<?php
$args = array(
'post_id' => 'new',
'field_groups' => array( 'acf_add_post' ),
'submit_value' => 'Add Post',
'return' => add_query_arg( 'updated', 'true', get_site_url()),// return url
);
acf_form( $args );
?>
my form for editing:
<?php
$args = array(
'post_id' => $post->ID,
'field_groups' => array( 'acf_add_post' ),
'submit_value' => 'Edit Post',
'return' => add_query_arg( 'updated', 'true', get_permalink() ),// return url
);
acf_form( $args );
?>
my pre_save_post function:
function my_pre_save_post( $post_id ){
// Create the post
$post = array(
'post_status' => 'publish' ,
'post_title' => $_POST['fields']['field_53701ca623c65'],
'post_content' => $_POST['fields']['field_53701c4623c64'],
'post_category' => $_POST['fields']['field_53b4955981c40'],
'post_type' => 'post'
);
if( $post_id != 'new' ) { // check if this is to be an edit instead of a new post
$post_id = wp_update_post( $post ); // update the post
}
else {
$post_id = wp_insert_post( $post ); // insert the post
}
return $post_id; // return the post (new or edited)
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
my exported php:
include_once('advanced-custom-fields/acf.php');
//Register ACF fields
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_add_post',
'title' => 'Add_post',
'fields' => array (
array (
'key' => 'field_53701ca623c65',
'label' => 'Title',
'name' => 'title',
'type' => 'text',
'required' => 1,
'default_value' => '',
'placeholder' => 'Title',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => 50,
),
array (
'key' => 'field_537e8061c8a97',
'label' => 'Description',
'name' => 'description',
'type' => 'text',
'default_value' => '',
'placeholder' => 'what\'s your post about?',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => 100,
),
array (
'key' => 'field_53b4955981c40',
'label' => 'Category',
'name' => 'category',
'type' => 'taxonomy',
'taxonomy' => 'category',
'field_type' => 'select',
'allow_null' => 1,
'load_save_terms' => 1,
'return_format' => 'object',
'multiple' => 0,
),
...
Hey Hube,
Working with the web is sometimes a serious uphill battle.
These are the scripts I ended up getting made, and you don’t have to worry about time outs.
Imports posts from root of WordPress install and automatically populates wp_posts and wp_postmeta. This script has a long way to go for categories, tags and mapping ids. Tested with 150,000 posts imported in 10 minutes.
https://github.com/muzza78/Import-Wordpress-Posts-from-CSV-to-MySQL
A few importers I used for different tasks.
https://github.com/muzza78/ratings-importer-to-wp_postmeta
Please use and fork at will. M
It is not possible to downgrade the data from ACF PRO to ACF4, however it is possible to use the export to PHP feature as both ACF PRO adn ACF4 use the same code format.
As for the original question, I’m not sure I understand what is going wrong.
What do you mean by set a qTranslate text field
?
I have tested qTranslate with ACF PRO and the ACF fields appeared on both languages. Perhaps you can include steps to replicate the issue?
This works better, no more update-struggles:
if(function_exists("acf_add_options_page")) {
acf_add_options_page();
}
if(function_exists("register_options_page")) {
register_options_page('Various');
register_options_page('Header');
register_options_page('Footer');
}
possibly a cleaner way around this:
public function htmlspecialchars_decode_array($array){
$arrayJsonEncoded = json_encode($array,JSON_HEX_QUOT | JSON_HEX_APOS);
$arrayJsonEncodedSpecCharsDecoded = htmlspecialchars_decode($arrayJsonEncoded);
$arrayJsonDecoded = json_decode($arrayJsonEncodedSpecCharsDecoded,true);
return $arrayJsonDecoded;
}
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.