I have added some custom fields to all attachments that are uploaded to the Media Library.
Text fields such as Location, Date, and some custom Tags.
I then have a custom post type of Photo Archive in which the admin can create a new post, upload as many images as they wish, which will then display on the single post page. The images are uploaded using the ACF Gallery field.
Each image will have a tag or tags, as well as Location and Date information attached to it.
What I now require is to get that information.
So far I have created this staging site: http://website-test-lab.com/sites/zuludawn/photographic-archive/
If you see where it says Filter by tags; this is where I need to get all the tags used from each image, from within the single post.
I did take a look at the code here but not sure where to put it or how to use it: http://www.advancedcustomfields.com/resources/how-to-get-values-from-a-media-attachment/
Any advice would be much appreciated.
I ended up using this which worked:
<?php
$posts = get_posts(array(
'numberposts' => -1,
'post_type' => 'page',
'meta_key' => 'display_in_carousel',
'meta_value' => '1'
));
if( $posts ): ?>
<?php foreach( $posts as $post ):
setup_postdata( $post )
?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
Answer:
echo $value['mime_type'];
Thanks
Hi
Sorry; that’s not the bit i’m stuck on.
It’s the actual meta_query loop that doesn’t appear to be working. I’m just wondering if my ‘value’ & ‘compare’ values are correct?
/*
* Query posts for a true/false value.
* This method uses the meta_query param to match the string “1” to the database value “1|0”
*/
$posts = get_posts(array(
'meta_query' => array(
array(
'key' => 'field_name',
'value' => '1',
'compare' => '=='
)
)
));
if( $posts )
{
foreach( $posts as $post )
{
setup_postdata( $post );
// ...
}
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
}
What should my value and compare values be?
Thanks
Solved my issue.
I added data attributes to the marker HTML:
<div class="marker" data-type="<?php echo $map_display_setting; ?>" data-zoom="<?php echo $map_zoom_level; ?>" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
And then set global variables:
var marker = $('.marker');
var zoomLevel = marker.data('zoom');
var mapType = marker.data('type');
And then altered the code below:
// vars
var args = {
zoom : zoomLevel,
center : new google.maps.LatLng(0, 0),
mapTypeId : google.maps.MapTypeId[mapType]
};
and
// only 1 marker?
if( map.markers.length == 1 )
{
// set center of map
map.setCenter( bounds.getCenter() );
map.setZoom( zoomLevel );
}
Did you figure out how to so this?
Looking at a solution to this with ACFPRO as well.
Would like to choose which WYSIWYG editors to remove P tags from.
Thanks
Figured out the answer, see below. This snippet is added to the widget class in my custom widget file.
if (get_field('upload_image', 'widget_' . $widget_id)) {
$attachment_id = get_field('upload_image', 'widget_' . $widget_id);
$size = "full";
$image = wp_get_attachment_image_src( $attachment_id, $size );
$alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
echo '<img alt="'.$alt.'" src="' . $image[0] . '" />';
}
Hi
I am a little lost on this, even with the linked page above.
I too have created a custom widget within my theme which uploads an image to echo out onto the sidebar.
I’m not sure how to check if the image has been uploaded and then if so, display the image. Do I need to add the code(and change it to suit) in my functions.php file?
I added the following to my widget class:
if ( get_field('upload_image', 'widget_' . $widget_id); ) {
echo 'IMAGE!!';
}
Thanks in advance
Found my answer here: http://support.advancedcustomfields.com/forums/topic/get-filesize/
Sidenote for the admins: I found this via a google search and not via the support forums search…
Worked for me, just what I was looking for thanks 🙂
Seems to have solved itself?? Strange. I came back to it after an hour and it was working, no warnings.
Thank you ever so much. I will take a look at this and reply as soon as possible.
Can you confirm that the images are showing for you? After a quick go, I still can’t get them to work?
I’m using V4 if that makes a difference? Perhaps V5 would work better?
That’s awesome.
I am going to update to V5 very very soon. This will solve my problem.
Thank you
Hi,
I have removed the ‘row’ flexible content field and created a new one labelled it as something completely different but it gave the exact same results, so that rules that out.
I’m at a loss on ideas. I may have to re-think how the backend is setup.
I will create a backup, rename the flexible content field and report back as soon as possible. It may not be today though.
Thank you so much for your replies today, you’ve been a great help. Hopefully, we can figure this out soon!
I’ll respond as soon as I can.
full_width_row is correct, I have just double checked.
If I change my flexible field from ‘row’ to something else, will I lose all my data? I have pages of it!
Screenshot attached.
My configuration is – Repeater field, Background colour, & image, Flexible Content.
I guessed this may be an issue, to use a sub field from the first repeater, inside the second… but I’ve tried to store it within a variable to use further down the code. This does not work.
There has to be a workaround?
I am currently using ‘image URL’ for the display of my image.
Thanks for your help.
Hi,
I want to create some custom, theme based, widgets using ACF also. My first stumbling block is probably the simplest! I wondered if you could point me in the right direction since you have previously done so.
So far, I’ve setup a Custom Field, but where it says Location, rules: Show this field group if… what do I choose?!
It’s probably something so simple!
Thanks in advance
This loop helped solve my problem:
@ladygeekgeek
I needed a radio button choice of Vimeo Video or Image for a slider.
I did this:
<?php if(get_field('hero_slider_slide','option')): ?>
<ul class="slides">
<?php while(has_sub_field('hero_slider_slide','option')): ?>
<?php if (get_sub_field('hero_slider_video_or_image', 'option') == 'Vimeo Video') { ?>
<li>
<?php echo '<iframe id="player_1" src="http://player.vimeo.com/video/'. get_sub_field('hero_slider_vimeo_video','option') .'?api=1&player_id=player_1" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>' ?>
</li>
<?php } else if (get_sub_field('hero_slider_video_or_image', 'option') == 'Image') { ?>
<li>
<img alt="<?php echo $alt; ?>" src="<?php echo $image[0]; ?>" />
<div class="grid-container">
<div class="grid-100 tablet-grid-100 hero-caption">
<p class="tagline"><?php the_sub_field('hero_slider_slide_caption', 'option'); ?></p>
</div>
</div>
</li>
<?php } ?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
Solved, see above post./
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.