At a quick glance it seems as though $double_encode should be set to false in the a couple of spots in the acf core when using htmlspecialchars:
http://php.net/manual/en/function.htmlspecialchars-decode.php
For now i just wrote a simple decode function that I run after get_field and before update_field:
public function htmlspecialchars_decode_array($array){
$newArray = array();
foreach($array as $arrayKey => $arrayVal){
$newArray[$arrayKey] = htmlspecialchars_decode($arrayVal);
}
return $newArray;
}
Just purchased this plug in and having the same issue with WP v3.9.1.
I have location rules set to display the field group if “Options Page” is equal to “Options”. The publish box shows up on the options page but the fields do not. Switched to 2014 theme to test but got the same results.
Any resolution to this? I see that the post above is two weeks old.
I found my custom field in the database with this code
`<?php
$mysql2 = new sql();
$post_id = $_GET[‘id’];
$sql2 = $mysql2->query(“SELECT * FROM wp_postmeta WHERE meta_key = ‘_campoadd’ LIMIT 1″,”mktiscom_cms”);
$result2 = $mysql2->fetcharray($sql2);
?>
<p><?php echo utf8_encode($result2[‘post_id’]); ?></p>
<p><?php echo utf8_encode($result2[‘meta_key’]); ?></p>
<p><?php echo utf8_encode($result2[‘meta_value’]); ?></p>`
however my custom field is an image, and al so have the field data.(http://mkt-in.com.br/home/noticia2.php?id=marcenaria-piracicaba) Know how the image q can assign this field?
Okay, the solution is really easy if you know basic PHP: Here we go:
<?php
$params = array( 'width' => 870, 'height' => 478 );
$image = bfi_thumb(get_sub_field('start_diashow_image'), $params); echo "<img src='$image'/>";
?>
“get_sub_field” is the key đ
I’m assuming that the custom field is associated with a post of some type.
Is would be the same principle that you did in the back-end. You enqueue a script, localized with the css file to load. Then when the script runs it can add the the stylesheet to the header. This would probably be the way you’d want it to work if you want to somehow add the stylesheed to the page during the “get_field()” or “the_field()” function calls.
Hi all, i’m not sure but i think i’m looking for the same thing.
In a flexible content area the user can select a page that is a parent.
– they are only shown a list of pages that are a parent.
Then for the actual content they select a page (using post object).
– they are only shown pages that are children of the parent they chose.
is this possible? the filter you linked to seems to require me to specify the parent pages form the outset & they might add more.
as always, thanks for the amazing product – and the new version rocks too!
Hopefully this will help, but I think I understand what you’re doing. I’m not exactly sure on the details of how to accomplish it, but I can give you a general outline.
Enqueue a JavaScript.
When your field is loaded or changes the script is run.
The script will look at the field and get the font that needs to be include then creates a new <style> element in the head of your document with the link to the correct CSS file.
You may also want to delete any previous <style> elements that were created when the user switches fonts.
Hi Everyone – I had this issue on the edit page and it only recently occurred. I realise this occurred just after I imported 100’s of post-types into WordPress and I had a field that was looking up the available pages for links. In fact I had this on a repeater.
Elliot – Any ideas if this can be ajax-ified so these pages are fetched when required we don’t run into these memory issues? Or perhaps another way to index links so this doesn’t cause an issue?
Everyone else – Either change the look up to be a text field and enter this manually or a bad compromise is to increase the memory limit: http://stackoverflow.com/questions/21680244/fatal-error-allowed-memory-size-of-268435456-bytes-exhausted-tried-to-allocate
Hope that helps
how to even get the data of a checkbox field with a wp_user_query? i tried
<?php echo implode(', ', get_field('country', $user_id )); ?>
as mentioned in http://www.advancedcustomfields.com/resources/field-types/checkbox/ but it shows me nothing :-/ in a normal query it works.
Thank you for your reply.
I created a wp template as you said and I named it “ACF Form” :
<?php
/**
* Template Name: ACF Form
*
* Description: A Page Template that adds a sidebar to pages.
*
* @package WordPress
* @subpackage Twenty_Eleven
* @since Twenty Eleven 1.0
*/
get_header(); ?>
<form method=âpostâ action=â#â class=âacf-form form-horizontal â id=âpostâ enctype=âmultipart/form-dataâ>
<?php
$args = array(
âpost_idâ => ânewâ,
âfield_groupsâ => array(1), //use wrong ID of your custom field Form so form fields will not get shown
âformâ => false
);
acf_form($args);
?>
<div data-field_type=âfileâ data-field_key=âfield_5343d9b2586f0fileâ data-field_name=âemailâ class=âfield field_type-text field_key-field_5343d9b2586f0fileâ id=âacf-fileâ>
<p class=âlabelâ><label for=âacf-field-fileâ>Image</label></p>
<div class=âacf-input-wrapâ>
<input type=âfileâ id=âmy_image_uploadâ name=âmy_image_uploadâ>
</div>
<input id=âsubmit_my_image_uploadâ name=âsubmit_my_image_uploadâ type=âsubmitâ value=âSubmitâ />
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I put the 2 functions in functions.php but I got a warning with this line :
add_filter(âacf/pre_save_postâ , âmy_pre_save_postâ );
=>Warning: Division by zero.
I have a category called “Box 1 accueil” and I have a list of articles (actually the issue is that the images image_1 and image_2 are not displayed because the upload button for image doesn’t work.)
Here is my code, it’s a part of the index.php page :
<div class="accueil">
<?php $esaat = "Box 1 Accueil";
$args = array('category_name' => $esaat);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) :
$the_query->the_post(); ?>
<div class="bandeau_bleu"><p><?php the_title();?></p></div>
<div class="image1">
<img src="<?php echo the_field('image_1'); ?>" />
</div>
<div class="image2">
<img src="<?php echo the_field('image_2'); ?>" />
</div>
<div class="clr"></div>
<div class="titre1"><?php the_field('sous-titre');?></div>
<div class="texte1">
<!--<p>
Le Centre éthique crée et développe des projets éducatifs et culturels internationaux.
Guidé par une philosophie humaniste, il organise des rencontres interculturelles et transmet
tout un ensemble de savoirs dans le sens d'une construction humaine qui respecte l'individu
et son environnement.
Il vise ainsi à concilier par ses actions l'éthique, la science, l'art et le sacré.
</p>-->
<p><?php $content = get_the_content();print $content;?></p>
</div>
<?php
endwhile;
wp_reset_query();
wp_reset_postdata(); ?>
</div>
I don’t know what to do with the “ACF Form”, the template page I created. So what I have to do now please?
Hi
in above solution we are not using acf form we are going to use htmlform mean create form in a wp page template with your required fileds for example if u create three fields in acf like Author Image Title Image then create similar form in html and
<form method=âpostâ action=â#â class=âacf-form form-horizontal â id=âpostâ enctype=âmultipart/form-dataâ>
<?php
$args = array(
âpost_idâ => ânewâ,
âfield_groupsâ => array(1), //use wrong ID of your custom field Form so
form fields will not get shown`
âformâ => false
);
acf_form($args);
?>
//file upload button
<div data-field_type=âfileâ data-field_key=âfield_5343d9b2586f0fileâ data-field_name=âemailâ class=âfield field_type-text field_key-field_5343d9b2586f0fileâ id=âacf-fileâ>
<p class=âlabelâ><label for=âacf-field-fileâ>Image</label></p>
<div class=âacf-input-wrapâ>
<input type=âfileâ id=âmy_image_uploadâ name=âmy_image_uploadâ>
</div>
<input id=âsubmit_my_image_uploadâ name=âsubmit_my_image_uploadâ type=âsubmitâ value=âSubmitâ />
The above form will be on u r wordpress page
Now copy the following function to your themes function.php
//img upload//
function kv_handle_attachment($file_handler,$post_id,$set_thu=false) {
<code>// check to make sure its a successful upload</code>
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . âwp-adminâ . â/includes/image.phpâ);
require_once(ABSPATH . âwp-adminâ . â/includes/file.phpâ);
require_once(ABSPATH . âwp-adminâ . â/includes/media.phpâ);
$attach_id = media_handle_upload( $file_handler, $post_id );
// If you want to set a featured image from your uploads.
if ($set_thu) set_post_thumbnail($post_id, $attach_id);
return $attach_id;
}
//New File Upload
add_filter(âacf/pre_save_postâ , âmy_pre_save_postâ );
function my_pre_save_post( $post_id ) {
// check if this is to be a new post`
if( $post_id != ânewâ ) {
return $post_id;
}
$field = $_POST['fields'];
$post_title = $_POST['fullname'];
$post_content = $field['edit_test2'];
// Create a new post
require_once(ABSPATH . âwp-adminâ . â/includes/image.phpâ);
require_once(ABSPATH . âwp-adminâ . â/includes/file.phpâ);
require_once(ABSPATH . âwp-adminâ . â/includes/media.phpâ);
$attachment_id = media_handle_upload( âmy_image_uploadâ, $post_id );
$post = array(
âpost_statusâ => âdraftâ ,
âpost_titleâ => $post_title,
âpost_contentâ => $post_content,
âpost_typeâ => âpageâ
);
$newpost_id=wp_insert_post($post);
if($newpost_id!=0)
{
add_post_meta($newpost_id, âpictureâ, $attachment_id );
// here u can add more fields which are present on u r form
}
}`
Quick results with 5.0.3, saving fields is still not working as expected, behaviour is different though. Will give more feedback as soon as I can test more.
Thank you so much for the response, Elliot.
Yes, I am writing about this plugin:
https://github.com/strickdj/acf-field-address
I think you meant to give me this link:
Creating a new field type
http://www.advancedcustomfields.com/resources/tutorials/creating-a-new-field-type/
https://github.com/elliotcondon/acf-field-type-template
I will give it a shot! (Unless there is a better way to create a group of fields similar to the functionality of this plugin.)
Also, others’ reference, similar to what I want to do — extract address field types from lat/lng Google Maps settings — you mentioned a good stackoverflow thread here (another here) about “reverse geocoding.”
I’ll try the field type template first. Thanks!
Ah, I see – this is mitigated by the use of quotes:
array(
'key' => 'course_tutors',
'value' => '"' . get_the_ID() . '"',
...
)
Hi all, won’t a LIKE query searching for post ID ‘1’ return a row with i.e. ’12’ (a post of ID 12), which would be an error?
If so, how can we avoid this error?
Champion! That fixed the issue! Thanks! Sorry for all the replies – we got there eventually! If there are any further issues I will post entire code blocks next time!
One quick question, is your advancedcustomfields.com/my-account/ a custom built area? Is it woocommerce with a custom theme?
Thanks again.
Hi
after u create front end form pls put following function in your function.php, add the required filed to post
add_filter(âacf/pre_save_postâ , âmy_pre_save_postâ );
function my_pre_save_post( $post_id ) {
// check if this is to be a new post
if( $post_id != ânewâ ) {
return $post_id;
}
$field = $_POST[‘fields’];
$post_title = $_POST[‘fullname’];
$post_content = $field[‘edit_test2’];
$post = array(
âpost_statusâ => âdraftâ ,
âpost_titleâ => $post_title,
âpost_contentâ => $post_content,
âpost_typeâ => âpageâ
);
$newpost_id=wp_insert_post($post);
if($newpost_id!=0)
{
$fullname=$_POST[‘fullname’];
$address=$_POST[‘address’];
add_post_meta($newpost_id,’FullName’, $fullname);
add_post_meta($newpost_id, ‘address’, $address);
}
}
You can also refer following article
http://www.advancedcustomfields.com/resources/tutorials/using-acf_form-to-create-a-new-post/
Hi here is solutions create html form
<form method=âpostâ action=â#â class=âacf-form form-horizontal â id=âpostâ enctype=âmultipart/form-dataâ>
<?php
$args = array(
âpost_idâ => ânewâ,
âfield_groupsâ => array(1), //use wrong ID of your custom field Form so form fields will not get shown
âformâ => false
);
acf_form($args);
?>
//file upload button
<div data-field_type=âfileâ data-field_key=âfield_5343d9b2586f0fileâ data-field_name=âemailâ class=âfield field_type-text field_key-field_5343d9b2586f0fileâ id=âacf-fileâ>
<p class=âlabelâ><label for=âacf-field-fileâ>Image</label></p>
<div class=âacf-input-wrapâ>
<input type=âfileâ id=âmy_image_uploadâ name=âmy_image_uploadâ>
</div>
<input id=âsubmit_my_image_uploadâ name=âsubmit_my_image_uploadâ type=âsubmitâ value=âSubmitâ />
// in function .php write following code
//Here we gather the files which sent by the HTML forms. and send it to //another function called kv_handle_attachement(). This is a simple function //this will help you to store the files to your wp uploads directory. Add //the following code into your Theme â functions.phpâ
//img upload//
function kv_handle_attachment($file_handler,$post_id,$set_thu=false) {
// check to make sure its a successful upload
if ($_FILES[$file_handler][‘error’] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . âwp-adminâ . â/includes/image.phpâ);
require_once(ABSPATH . âwp-adminâ . â/includes/file.phpâ);
require_once(ABSPATH . âwp-adminâ . â/includes/media.phpâ);
$attach_id = media_handle_upload( $file_handler, $post_id );
// If you want to set a featured image from your uploads.
if ($set_thu) set_post_thumbnail($post_id, $attach_id);
return $attach_id;
}
//New File Upload
add_filter(âacf/pre_save_postâ , âmy_pre_save_postâ );
function my_pre_save_post( $post_id ) {
// check if this is to be a new post
if( $post_id != ânewâ ) {
return $post_id;
}
$field = $_POST[‘fields’];
$post_title = $_POST[‘fullname’];
$post_content = $field[‘edit_test2’];
// Create a new post
require_once(ABSPATH . âwp-adminâ . â/includes/image.phpâ);
require_once(ABSPATH . âwp-adminâ . â/includes/file.phpâ);
require_once(ABSPATH . âwp-adminâ . â/includes/media.phpâ);
$attachment_id = media_handle_upload( âmy_image_uploadâ, $post_id );
$post = array(
âpost_statusâ => âdraftâ ,
âpost_titleâ => $post_title,
âpost_contentâ => $post_content,
âpost_typeâ => âpageâ
);
$newpost_id=wp_insert_post($post);
if($newpost_id!=0)
{
add_post_meta($newpost_id, âpictureâ, $attachment_id );
}
}`
Let me know if u have any question , its works perfectly fine
Thanks
hi
have you tried some code pls share I will suggest you change it seems all of your requirements are related PHP coding
If your requirements are limited to following only
How not to show the library files when uploading the front end?
1) create html form to upload image
http://www.kvcodes.com/2013/12/create-front-end-multiple-file-upload-wordpress/
2) How to define the format of files that can attached?
Refer following code here u can limit type file to be uploaded
3) How to limit the amount of files that can be attached?
by following code u can limit the size of file
<?php
$allowedExts = array(“gif”, “jpeg”, “jpg”, “png”);
$temp = explode(“.”, $_FILES[“file”][“name”]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
} else {
echo "Invalid file";
}
?>
Thanks that answered my question. Funnily enough I have already created a custom taxonomy for my email templates so I should be sorted there. Cheers for the advice đ
I have a client I just created a site for with a products CPT that has a related products field. They have nearly 800 products and all of them are listed… in a “more” sorta way. When you scroll to the bottom of the current list the next few are loaded. The search works perfectly and loads pretty quickly.
I would suggest that you also create a custom taxonomy for your email templates that allows the email templates to be sorted into “categories”. I’d probably name the taxonomy ’email-template-types’ đ In the future, when there are 1000’s or templates this may help the users find them faster.
Just check the wordpress update process. After installing a new version of wordpress, the process goes through every database of the network (5 websites each step) and does the required updates.
The multisite function of wordpress is absolutely powerful.
I’ll be creating the pages and accounts for this particular project, so it’s simpler than what you’re doing. But another project requires user-driven account creation and we’re using Gravity forms as well…so we’ll look into your solution.
I also thought that BuddyPress would do all of this…surprising that it doesn’t.
Good to know about Tabby Tabs…looks useful.
Thanks again!
Seth
I had to write a converter script to update some fields and this is how I set up the Google map field $value array. Worked fine.
$field_name = "field_53bdd058c84a8";
$value = array("address" => $address, "lat" => $lat, "lng" => $lng, "zoom" => $zoom);
update_field($field_name, $value, $this_ID);
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.