Great Hetgelaat!
Please mark my answer as the topic solution tho 🙂
Hi Phil,
Not at the moment no.. It could be a feature request tho!
No I think this would be a bug if it’s not something that’s colliding within your own setup.. have you tried disabling all other plugins (blablabla standard wp testing)? The repeaterfields are supposed to be able to nest so your setup should work.
Hi!
I think you could do something like this:
add_post_meta($post_id, '_thumbnail_id', $attachment_id);
since the posts featured image is really just a meta value (of course the actual image has to be uploaded and have its own “post” in wp_posts)
Hi!
If each post had it’s own date field not in a repeater it’d been easier.. but as it is I suppose you’ll have to do something like this:
<?php if(get_field('matches')):
$i = 0;
$today = date('Y-m-d'); //This has to match the format of your date field
?>
<ul class="matches_list">
<?php while(has_sub_field('matches')): ?>
<?php if(strtotime($today) <= strtotime(get_sub_field('date'))){ ?>
<?php if($i < 5){ ?>
<?php $i++; ?>
<li class="match">
Hove (<?php the_sub_field('teams'); ?>) <strong><?php the_sub_field('hove_score'); ?> <span style="color: #A2224C; font-weight: bold;">-</span> <?php the_sub_field('opponent_score'); ?></strong> <?php the_sub_field('opponent'); ?><br><?php the_sub_field('date'); ?> @ <?php the_sub_field('location'); ?>
</li>
<?php } ?>
<?php } ?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
This will not check to make sure the five chosen are the latest ones and it’s possible that due to the repeaterfield arrays setup you will end up with the five oldest ones (which have a date later or equal to today). If so you’ll have to first get the repeaterfield into a variable and do an array_reverse() on it!
Hi Hetgelaat!
I think you’ve got a point so I made some alterations to the relationship-field myself 🙂 This will allow you to choose wether to have it return the post objects or just ids
I’ll attach it here. In order to use it simply drop it into plugins/advanced-custom-fields/core/fields and replace the relationship.php
@elliot , I will push this fork for you on github so you can choose to add it in or not 🙂
I do not think that the ACF galleryfield works in the same way as wordpress built in gallery function.. Meaning that when you create a ACF gallery you can not expect the same functionality as with an wp gallery.. however this gives you immensely more freedom to set up the gallery as you like it (with a custom lightbox or whatever)
Hi!
I honestly think you’ll be better of creating this yourself..
simply do an update_post_meta on the wp_save_post hook.. something like this (not tested):
function save_book_meta($post_id) {
$slug = 'book'; //CHANGE THIS TO THE SLUG OF YOUR POST TYPE
/* check whether anything should be done */
$_POST += array("{$slug}_edit_nonce" => '');
if ( $slug != $_POST['post_type'] ) {
return;
}
if ( !current_user_can( 'edit_post', $post_id ) ) {
return;
}
$current_user = wp_get_current_user();
update_post_meta($post_id, 'latest_author', $current_user-> display_name);
}
add_action( 'save_post', 'save_book_meta');
This will save the current users display name as a custom field called “latest_author”.
change the_permalink to get_permalink and you should be all set 🙂
The subfields doesnt really have a specific ID.. However you can do a loop counter in your while(has_sub_field()) and use that to create custom ids..
example:
<?php
$i = 1;
while(has_sub_field('myfield')):
echo '<div id="item-' . $i . '">' . get_sub_field('mysubfield') . '</div>';
$i++;
endwhile;
?>
This will give your items an id of item-1, item-2 etc. so in your anchor you can do:
<a href="#item-2">link to second item</div>
Im not sure what you want..
If you remove those custom fields values that you created other than the field to the right it should work with the code I gave you.
If you want to learn how to use the repeaterfield add on you can have a look here: http://www.advancedcustomfields.com/resources/field-types/repeater/
It’s possible that you’ve messed up the field so if it still doesnt work you can try to rename the field like “user2_2” or something and try it again.
ahhh..
You’ve confused wordpress regular meta boxes with ACFs..
What you’ve done there is input the values in wordpress default meta boxes which will probably mess upp ACF.
As you can see to the right you have the actual field! This is where you should set your author. delete those other..
If you want to be able to set multiple authors you should have a look at the add on repeaterfield here on ACF and use that.
could you post print screens of your setup in ACF and in a author page (admin)
could you make sure that user2 is the correct fieldname and is this field on a regular post or something special?
(int)get_field(‘user2’)
says to retrieve the fieldvalue of fieldname user2 and turn it into an integer. So if the value is “20” it’ll be 20 as an integer.
Then you use get_userdata which is a wp function and takes the users id which is correct..
So there’s nothing wrong with the code, it has to be in your setup.
$userID = (int)get_field('user2');
$theuser = get_userdata($userID);
echo 'Username: ' . $theuser->user_login;
remove the ” around 20.. You want it as an integer and not a string.
so $user2 = 20; should work..
if you’re in a post and want the author which you’ve set via the user field in ACF you can just retrieve it like normally in the loop:
$userID = get_field('YOUR USER FIELD FIELDNAME');
$theuser = get_userdata($userID); //This contains all the users basic info as an object
Like elliot says,
You should put the setup_postdata(); INSIDE the foreach loop. My bad wasnt thinking 🙂
Hi Michelle,
You have to add it inside the loop.. And of course the function should only be added once in functions.php.
Also, make sure you change the fieldname (the first parameter) to the correct one AND also that the field is set to output the image ID.
If you want to use it outside of the loop you could change it to this:
<?php
global $post;
echo get_image_with_alt('NAME OF THE IMAGE FIELD', $post->ID, 'thumbnail'); ?>
Hi Jplew!
It’s not currently supported to move fields but here’s a topic with pretty much the same question:
http://support.advancedcustomfields.com/forums/topic/move-fields-from-one-field-group-to-another/
Hi!
Youve not pasted anything about the ACF fields but I’m guessing that these appear below that code and they’re attached to a different post..
So what you need to do is put this after the endforeach:
wp_reset_postdata();
Hi!
Make sure that your image field is set to return the image ID and not the URL or object!
Hi @oxygensmith,
You’ll have to setup postdata for it to work without specifying the second post id parameter..
so put this before the if statement:
setup_postdata();
and then this right after the foreach loop
wp_reset_postdata();
Hi Math.. Perhaps you’re calculating wrong *hohoho*
In all seriousness, fetching a users username isn’t part of ACF but you can do it like this ( for the currently logged in user)
<?php
if(user_is_logged_in()){
$currentuser = wp_get_current_user();
echo $currentuser->user_login;
}
?>
EDIT: Sorry about the bad pun, I’ve had a bit of whisky..
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.