So simple. Thank you John!
If anyone need a solution, i’ve used one JQ line:
(function($){
$('.input-field]').insertAfter('.acf-field');
})(jQuery);
Hi John,
I thought it hooks into the form function. Perhaps i’ll use JQ to for this. Thank you.
John Huebner,
Just found this topic, thank you for writing this!
Hi James
An Update!
After further investigation i see that fields in widgets are stored as options in the wp_options table. I was able to pull the values using the following code:
echo get_option('widget_' . $args['widget_id'] . '_field_name');
The only thing is that field value is not changing live in Customizer, only after i hit the “Save & Publish” button and refreshing the page on the front end.
More work needed with get_option().
Hi James
Thank you for your reply.
Unfortunately it did not work and returned nothing. I’m trying to pull the field value in a widget which is placed on the “Your latest posts” page as index.php.
I’ve also tried using the get_option('page_for_posts');
and get_option('page_on_front');
to get the id of this page. If i just print the get_option()
function it will return the id, but inside the get_post_meta()
it always return an empty string.
Hi James,
Thank you. Just sent.
Update:
As it seems the get_field in this case need the post id as a second parameter:
get_field( 'dummy_slug_custom_field', $post_id );
I have the same thing using the acf/save_post. Field value saved only after i hit the Update button a second time.
Hi James
I’m using this code and it works, but only if i hit the Update button the second time, on the front end or in the backend. Do you know why it does not make any affect after the first save?
+1!
Clone field is a great feature and it’s need the width option.
Hi James,
I was also thinking that way. Thank you.
Hi James,
This makes sense and more than this, it seems so obvious and simple. Really appreciate your help. Thank you.
Hi James,
Thank you for your reply.
By “confusion” you mean the human factor, not DB conflicts?
Hi James
Thank you for your help, i’ll give it a try.
I’m trying to do the same thing. Have you ever got it working?
Opened a support ticket.
Hi James,
Thank you for your reply. Just opened a ticket.
Hi Elliot
To continue this subject; Is including the PRO version invisibly is mandatory or can we include it as a plugin using the TGM class, so the users can update the plugin when you release new updates?
Will the ACF_LITE constant still be available?
Thank you.
Hi Elliot
It does not make a difference, the function still returns an error.
The echo $post->ID;
returns an ID of the current single post i’m viewing.
I had and idea of making a field, true/false maybe, and assign it to post edit page with location rule. As soon as the post is selected in the Relationship field and page is updated, this true/false is getting the “true” value. Then in the widget, i can use this field in WP_Query as meta_key parameter. The schema looks like this:
Relationship fields in Flexible Content (Page) → True/False field (Post) → Widget.
Do you think something like this is possible using Filters?
I just don’t have another ideas how to sort out the situation.
Thanks again for your help.
Hi Elliot
Widget loads in all pages with sidebar; homepage, single, categories.
When i use get_field_ID();
above global $post;
i get an undefined function error, in a case of ACF field i get the “false” result.
Another test i made is commenting the if statement: if( $featured_posts_sidebar ):
i get the loop error: Invalid argument supplied for foreach()
Hi Elliot,
I get bool(false)
on this field
Hi Elliot, thank you for getting back to me.
I’m using the Relationship field with Flexible Content to create a list of selected posts which is called Featured Posts:
<?php
while( has_sub_field( 'page_builder' ) ):
if( get_row_layout() == 'featured_posts' ):
get_template_part ( 'builder/featured', 'posts' );
endif;
endwhile;
?>
The loop inside featured-posts.php looks like this:
<?php
$featured_posts = get_sub_field( 'featured_post_add' );
if( $featured_posts ):
foreach( $featured_posts as $post ): ?>
<article>
...
</article>
<?php
endforeach;
wp_reset_postdata();
endif;
?>
Everything works great.
Now what i’m trying to do, is to output the exact same posts, added in this Relationship field, in a widget. I have created a widget file featured-posts-widget.php which i drag into the sideabr. The thing is that the posts are not showing up and the widget is blank, besides the title, no matter what type of loop or a query i use. The code among others i tried is:
<?php
global $post;
$featured_posts_sidebar = get_field( 'featured_post_add' );
if( $featured_posts_sidebar ):
foreach( $featured_posts_sidebar as $post ): ?>
<article>
...
</article>
<?php
endforeach;
wp_reset_postdata();
endif;
?>
In the widget i use get_field and not get_sub_field. Maybe using WP_Query and not the foreach loop would be a solution, but what parameters do i have to use?
Can you point me to the right direction?
Hi Elliot
Thank you!
Thank you very much for your help bootsz, much appreciate it. It was the perfect solution.
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.