I cant be sure but isn’t the reason why elliot uses a random field key string to avoid issues where the user has entered the same field name for multiple fields.. I don’t think there’s a check for duplicate field names when the user creates his fields and by using a random string instead ACF wont make the two clash.
This is just my speculations tho 🙂
Hi!
You should use the post types slug for the post_type argument.. which I’m guessing would be portfolio-item?
The reason why your ACF field is not being displayed is because you’re using the_field which tries to echo the result itself. In this case you’re already doing that so replace the_field with get_field and you should be golden!
Hi!
You can do like this, where the $imageID is the ID of the image retrieved from ACF:
$alt_text = get_post_meta($imageID , '_wp_attachment_image_alt', true);
Hi!
Since you’re probably outputting the repeaterfield in a while loop you can use a counter for the steps:
<?php
$i = 1;
while(has_sub_field('myrepeaterfield')):
?>
<p>Step <?php echo $i; ?></p>
<?php
$i++;
endwhile;
?>
I’ll agree in saying that relevanssi is a good plugin for extended search in WP.. I do think however that this is very much a question for the relevanssi support forums rather than ACF 🙂
Well that’s not entirely true.. It is out of the scope of ACF to automatically add default values to posts depending on category.. However if there’s no apparent reason to why the field_objects checkbox values are in one long string you could create a fork on the ACF repo on github and fix it yourself and hope for it to be included in the next version 🙂
sounds wierd..
My recollection of the field object with a checkbox was an array with each value. But I haven’t had a look at it in some time..
I suppose you could copy the field from the ACF core and make your own addon where you put the values in an array instead so that you can use them as you please
You say the default values are produced as a string.. I believe they’re like this: default1, default2, default3 etc.
If you need this as an array why not simply use php explode?
$myarray = explode(', ', $default_values);
If the string does not contain a space just remove that from the first parameter of the explode 🙂
Good morning,
So I’ve taken a look at your file and I can’t even find any reference to that which you are doing? Where in the code is this supposed to happen since there’s not anything there?
In any case. The markup was chaos so I took the liberty of cleaning it up a bit for you with proper indents and a missing end div-tag.
http://pastebin.com/PdJ6GAb2
As roberto says.. you need to put this inside php tags for the code to run.. or it will just be treated as a regular string!
This applies to everything that’s not HTML or a string.
the do this inside the loop but outside any if statements:
print_r(get_field('stock'));
And post the result here
<?php
if(in_array('In Stock', get_field('stock'))){
}else if(in_array('Forthcoming', get_field('stock'))){
}else if{in_array('Out of Stock', get_field('stock')){
}else{
No selected
}
?>
This should work then according to http://www.advancedcustomfields.com/resources/field-types/checkbox/
which I assume works the same as radiobuttons..
Great to hear 🙂 Let us know
Okay, It’d be much easier to help you if we could actually see the whole code in context 🙂
Nc, Ic (I see) .. hoho..
Then I suppose it’s a bit more complicated.. so dynamic that you can’t even retrieve a specific field from the ACF interface?
With get_field_object you should be able to retrieve the specific checkbox with it’s values if that’s what you need.
Ah! We’ll it seems your wp_query that comes after the regular loop overwrites the post object with this: $wp_query->the_post();
You can try putting wp_reset_postdata(); right after the endwhile for that loop.. If that does not work try putting the value in a variable inside the regular loop that comes before the new wp_query and then access the variable where you need it 🙂
Isn’t it so that when jut one checkbox has been checked the return is not an array but rather just a string.. So if you know that your user will always just check one (if so Id use radiobuttons instead) you should just check it like a regular string..
<?php if ('in_stock' == get_field('stock')) { ?>
STUFF HERE
<?php } ?>
hi!
Is it uni-title or uni_title? Make sure those match since you’ve written both in your description..
It should not matter what template you’re using it on, but I guess that depending on where in the template you use it you might need to provide the post id as well.. try this:
<?php global $post; ?>
<h3><?php the_field('uni_title', $post->ID); ?></h3>
Hi NC,
Since you’ve set the checkbox default value yourself when creating the ACF field you don’t really need access to the array..
If the value is just from one checkbox it will be saved as a string (if I remember correctly) and you can just manually write that out as the info to be saved without accessing the checkbox actual values.. Since it’s the same value as for the default value when ACF loads it it will recognize it as the default being checked while in reality you put it in there manually 🙂
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.