Thanks Jamie and Elliot. This answered my question
For anyone else interested in passing field data between pages while using a drop down menu to connect the pages together, here’s one way to do it:
Get field data from another page via drop down menu:
Page A (master page)
Page B (sub-page): Linked to Page A via drop-down menu
Create a post object field on Page B’s ACF called ‘select_page’
In order for Page B to access field data from Page A:
Add something like this in Page B’s php code:
<? $pages = get_field('select_page');
get_field('content_from_page_A', $pages->ID);
?>
Thanks, Daniel. That’s really useful info which I’m sure I’ll use in the future.
However, right now I’m trying to do this through separate forms. That is, I have multiple forms on my site but they each update a different post-type.
This is in my functions.php:
// ACF SAVE NEW POST
function my_pre_save_post( $post_id )
{
// Create a new post
$post = array(
'post_status' => 'publish' ,
'post_title' => $_POST['fields']['field_52d978ea24ac7'],
'post_type' => 'location' ,
);
// insert the post
$post_id = wp_insert_post( $post );
// update $_POST['return']
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
This makes sense and works perfectly for one form — but if I add a second form to update a second post type, it doesn’t work. What do I need to modify so that I can have more than one form?
Cheers,
Enrico
I found this tutorial today and figured I would take a shot at writing what I needed. “http://www.wpactions.com/1028/how-to-create-dropdown-list-button-in-tinymce-toolbar/”
I was successful in creating a simple dropdown that would allow you to pick from ACF from your options page. I have only tested it with the text field since that’s all I am using it for but I believe it should work for quite a few fields.
Plugin File (acf-dropdown-shortcode.php)
<?php
/*
Plugin Name: Advanced Custom Fields: Dropdown Shortcode
Plugin URI: http://www.andresthegiant.com
Description: Create a dropdown list of Advanced Custom Fields in the tinymce toolbar
Author: Andres The Gaint
Version: 0.1
Author URI: http://www.andresthegiant.com
*/
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'advanced-custom-fields/acf.php' ) ) {
add_action('admin_head', 'my_print_shortcodes_in_js');
add_action('admin_head', 'my_add_tinymce');
function my_print_shortcodes_in_js(){
?>
<script type="text/javascript">
var my_shortcodes = [
<?php
$fields = get_fields('option');
if( $fields )
{
foreach( $fields as $field_name => $value )
{
// get_field_object( $field_name, $post_id, $options )
// - $value has already been loaded for us, no point to load it again in the get_field_object function
$field = get_field_object($field_name, false, array('load_value' => false));
echo "'" . $field_name . "' , ";
}
}
?>
];
</script>
<?php
}
function my_add_tinymce() {
// global $typenow;
// if(!in_array($typenow,array('post','page')))
// return ;
add_filter('mce_external_plugins', 'my_add_tinymce_plugin');
add_filter('mce_buttons', 'my_add_tinymce_button');
}
function my_add_tinymce_plugin($plugin_array) {
$plugin_array['acf_drop'] = plugins_url( 'dropdown-shortcode.js',__FILE__ );
return $plugin_array;
}
function my_add_tinymce_button($buttons) {
array_push($buttons, 'acf_drop');
return $buttons;
}
}
?>
Plugin JS File (dropdown-shortcode.js)
(function() {
// Makes ACF names readable
function unSlugify(Text)
{
return Text
.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();})
.replace(/_/g, " ")
;
}
tinymce.create('tinymce.plugins.acf_drop', {
init : function(ed, url) {
},
createControl : function(n, cm) {
if(n=='acf_drop'){
var mlb = cm.createListBox('acf_drop', {
title : 'ACF Options',
onselect : function(v) {
if(tinyMCE.activeEditor.selection.getContent() == ''){
tinyMCE.activeEditor.selection.setContent( v )
}
}
});
for(var i in my_shortcodes)
mlb.add(unSlugify(my_shortcodes[i]), '[acf field="' + my_shortcodes[i] + '" post_id="option"]');
return mlb;
}
return null;
}
});
tinymce.PluginManager.add('acf_drop', tinymce.plugins.acf_drop);
})();
Hope this can help someone else
Nothing happens on click.
This is the console on load:
Consider using 'dppx' units instead of 'dpi', as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. In media query expression: only screen and (-webkit-min-device-pixel-ratio: 2), not all, not all, not all, only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) post.php?post=28125&action=edit:1
Consider using 'dppx' units instead of 'dpi', as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. In media query expression: print, not all, (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi) post.php?post=28125&action=edit:108
Uncaught ReferenceError: tinyMCE is not defined post.php?post=28125&action=edit:62
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
Here’s the code causing the TinyMCE error:
<script>
jQuery(document).ready( tinymce_excerpt );
function tinymce_excerpt() {
jQuery("#excerpt").addClass("mceEditor");
tinyMCE.execCommand("mceAddControl", false, "excerpt");
tinyMCE.onAddEditor.add(function(mgr,ed) {
if(ed.id=="excerpt"){
ed.settings.theme_advanced_buttons2 ="";
ed.settings.theme_advanced_buttons1 = "bold,italic,underline,seperator,justifyleft,justifycenter,justifyright,separator,link,unlink,seperator,pastetext,pasteword,removeformat,seperator,undo,redo,seperator,spellchecker,";
}
});
}
</script>
I disabled all plugins except ACF and its add-ons to see if that would fix the error, but it did not. Any ideas?
Hi Elliot,
I’m talking about the front end of the website. It shows the date formats in English, but my WordPress installation is in Dutch.
I use the standard jQuery datepicker function from ACF but not the add-on. Which one should I use, or doesn’t that make any difference?
Thanks!
Thanks for the feature request, but this would be difficult and heavy to add into the ACF plugin.
A better alternative is to write some custom CSS or JS which will hide the metaboxes you want.
I’ll add this to the to-do to add in a custom action which you could hook into the acf field group CSS, to then append some custom CSS when a field group is shown.
Thanks
E
Hi @incredimike
I think your right, there was a time when ‘convert to HTML’ was the default, but due to user request this was changed.
Thanks for posting the answer.
Cheers
E
Hi @sdawson26
Yes, all that is needed is to hook into the GF save, and modify the value before it is saved to the DB.
The quest is, ‘does GF insert the image data into the DB (like WP), or does it only save the file and provide a URL to see it’?
If GF does not save the DB data, then ACF can’t load the attachment. You could easily write some code which uses the url value to get a path to the image. Use this path to then insert the image into the db through some of WP’s built in image functions (google how to write a custom file uploader in WP)
Then, once you have the data inserted and an attachment ID, return this to GF for it to save, and then ACF will read it!
Hope that helps.
Thanks
E
Hi @schmidtie04
I can see that the field in question is saved to a taxonomy term. Perhaps this is where the problem lies.
Please read the docs on how to get a value from a taxonomy term:
http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/
Thanks
E
If you can confirm they are working on another test site, then the issue must be specific to the website in question.
Perhaps you have some code which is preventing ACF from reading in these post types?
Please double check that the settings of the field types are 100% the same.
Thanks
E
Hi @foxsk8
Please be sure to read who the developer is of a plugin. This is a 3rd party plugin which is not supported by me (I didn’t create it).
Yes, the ACF taxonomy field does not currently contain the ability to add a new term. If this is required, then why even use custom fields at all? Why not just use the default WP taxonomy metabox which appears on the post?
Thanks
E
Hi @GoldenGekko
Your comment is not correct, an HTML element does not require JS in the ‘onclick’ attribute to work. jQuery uses JS in a separate file to attach JS events to elements in a cleaner fashion.
As for the issue, please check your console log for any JS errors when you click or on page load.
Thanks
E
Hi @mswas
Thanks for the screenshots. To achieve the 3 questions above, you will need to add a field to the user. This field will contain the ‘reviews’ number.
For now, you can ask your editors to manually edit this number when they post a new review (edit profile, update custom field and save profile). You could also write some code to do this automatically, but lets talk about that later (after you have achieved 1,2,3 above).
With each user now containing a custom field for the ‘reviews’ number, you can use the WP_User_Query to query the users and display them in a list.
You can also output the user custom field (checkout the docs for more info on users) and sort them based on the custom field value based on teh custom field value!
This should solve all your problems!
basically, it won’t be possible to achieve the above with your current data setup and the user custom field is needed.
Thanks
E
Hi @daniel@push10.com
Thanks for the request. I’ll add this to the to-do and let you know what I come up with.
Thanks
E
Hi @sdawson26
ACF requires the value (for an image field) to be the attachment ID. If you can use the GF filter to modify the value and change it from the image URL to the image ID, then yes, this will work!
Thanks
E
Hi Elliot, that was just a general question, not that you already cover that kind of functionality in one of your premium plugins (i’ve overseen that already in one of my previous posts in here where you’ve pointed me to the repeater field – thanks again for that, the repeater field rocks). But indirectly you’ve answered my initial question here, since otherwise you’ve pointed me to one of your plugins. 😉 And I’ve already asked on stackoverflow but no useful answer yet. But finally had a new idea today which actually might work – implementing it right now and it seems to work. I only might have a follow up question, 100% acf related, later tonight, if I am unable to manage to get one specific thing working. But i will open a separate thread for it then. 😉 Thanks for now. Best regards Ralf
Just thought I would add to this as I have experienced the same issue.
I use the flexi field for a similar functionality and have a lot of sub fields with conditional logic. The lag became quite high after a few fields had been added to the page and I found that the main culprit was a post link field inside repeater rows. I disabled that and the conditional logic and everything was smooth again. This was developing locally as well.
Composer rules! Here’s more info: http://roots.io/wordpress-plugins-with-composer/
In the meantime I am using the following for the acf-repeater composer.json file.
{
"name": "advancedcustomfields/repeater-field",
"description": "Break free from static inputs and create multiple rows of loop-able data",
"keywords": ["wordpress", "plugin", "advancedcustomfields", "acf", "repeater"],
"homepage": "http://www.advancedcustomfields.com",
"license": "This software is NOT to be distributed, but can be INCLUDED in WP themes: Premium or Contracted.",
"authors": [
{
"name": "Elliot Condon",
"email": "[email protected]",
"homepage": "http://www.elliotcondon.com"
}
],
"type": "wordpress-plugin",
"require": {
"composer/installers": "v1.0.6"
}
}
Hi @elliot
Yes, I’m trying to get an array, but can’t figure out how. When I print_r, as you requested, I get one sad ID.
WP_Post Object
(
[ID] => 229
[post_author] => 3
[post_date] => 2014-01-17 04:25:49
[post_date_gmt] => 2014-01-17 09:25:49
[post_content] =>
[post_title] => Usability
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => usability
[to_ping] =>
[pinged] =>
[post_modified] => 2014-01-20 09:46:18
[post_modified_gmt] => 2014-01-20 14:46:18
[post_content_filtered] =>
[post_parent] => 0
[menu_order] => 0
[post_type] => values
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
I’ve been trying to get 229, 233, 150, 239, 134, 221, 223,
because I was able to echo it once…
<?php
// Values this strategy does NOT impact
// strategy_impact = repeater
// impact_value_select = post_object
// custom_value_description = text not used here, but elsewhere
if ( get_field('strategy_impact') ): ?>
<?php while(has_sub_field('strategy_impact')) : ?>
<?php
$impact_values = get_sub_field('impact_value_select');
$impact_IDs = array($impact_values->ID);
$impact_IDs_comma = implode(",", $impact_IDs); ?>
<?php $the_thing = $impact_values->ID.','; ?>
<?php
echo $the_thing
?>
<?php endwhile; ?>
I get 229, 233, 150, 239, 134, 221, 223,
I wish I could get that into the “post__not_in” parameter, but after the endwhile …
Sorry if I’m going the taking the long route in the wrong direction.
What I’m really trying to accomplish is to get a full list of the “values” post_type but change the class/appearance of the posts based on whether or not they are post_objects of the current page, as determined by the strategy_impact sub-field.
Even if what I’m trying here works, it’s not the ideal way to do it because it generates two lists instead of one — one that’s all the objects, one that’s not all the objects — instead of one list where objects are given different classes than the others.
Elliot,
Could you please elaborate on the “GF saves a URL instead of a link”?
If i pass a text field with the value…
<img src="http://website.com/image.jpg">
… instead of …
http://website.com/image.jpg
…would that do the trick? Because I’m having no luck with that.
Gravity forms has a hook called a pre_form_submission that can manipulate the value being sent through the form. I just need to know what the variable that I’m posting to the field should be in order for ACF to pick up the image upon GF submission.
@elliot,
I am having the same problem as @emilygutierrez. I am just using the example page from your site: http://www.advancedcustomfields.com/resources/getting-started/displaying-custom-field-values-in-your-theme/
and am pretty much getting the same result: just the title with no data.
I created a Custom Post Type using CPT UI and called it heroimage. I then created a new Custom Field with two entries, custom_title (text) and hero_image (get by URL). I saved the sample page to my theme directory under the title heroimage.php. I entered the data in my custom field and saved it. When I click on View Hero Image, I see only the title, no picture or custom title.
I have looked into this on various other sites and it seems that the database has to be queried in order to produce results if you are calling them on a page. But your example makes it look like no database query is necessary. I am confused! Please help, because I would really like to master this plugin.
Elliot, opening the browser’s console, i see that clicking on these flexible layout buttons does not even attempt to run any javascript…
Here is the HTML code for the one of the layout buttons:
<a title="Add New Layout" href="javascript:;">Add New</a>
All other layout buttons are coded the same…
Does this help arouse any ideas??
Thnx
Hi Elliot,
i’m using this code at the moment.
<?php if(get_field('maps'))
{
?>
<iframe width="550" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=<?php echo the_field('maps'); ?>;t=m&z=10&iwloc=A&output=embed&iwloc=near"></iframe>
<?php
}
?>
There are no specific JS errors on the page.
Joost
Hi there Elliot,
Thanks for getting back to me.
I think I was a little unclear with my query, forgot a key word!
The Custom Post Types do indeed appear under “Page” which is great, however the Custom Post Type posts, which appear under “posts” in previous sites I’ve created, are not appearing anywhere within the location dropdowns.
They’re all set up the same way as before (and I set up a test on another new site and it seems to be working), so I’m a tad confused as to what may be causing the issue.
Any ideas?
Thanks in advance.
Let’s start with a ref,I am trying to follow tutorial:http://www.advancedcustomfields.com/resources/tutorials/creating-a-front-end-form/
Clarifiaction when I say I am setting 'post_id' => $post->ID
to a specific number i mean changing this to 'post_id' => 464
found on permalink AND added $options variable to the same file of the themes’templates’ php code.
That works, however you normally need to set the post_id from a page that queries wp_query and comes up with $post=>ID
. You also normally need not to use the <?php the_post(); ?>
and instead add a textarea or WYSIWYG to actually change the content&title.( i guess with the html_after_fields property/attribute)
It is extraordinary and seems improbable that you took spended so much effort to render acf_form and not have included standardfields, so please check your referrences and documentation for any hints or refferences
I also needed to display a list of posts with an edit link to point to the page using the template that will ‘fetch’ the $post=>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.