@hube2 Hi man! How would I solve the same problem for an gallery field?
I use
<?PHP if(get_field('fotos')) : $images = get_field('fotos'); ?>
<img src="<?php echo $images[0][sizes][home]; ?>" alt="" />
<?PHP endif; ?>
And [08-Aug-2017 16:29:17 UTC] PHP Warning: Illegal string offset ‘home’ in
Thank you @hube2 , I don’t have much experience with php, so I’m going to “beat” enough to understand, but I appreciate your help.
Hi,
<?php echo $img['sizes']['medium-width']; ?>
dont work
<?php echo $img[0]['sizes']['medium-width']; ?>
work, why?
Ok, thanks @acf-support James! xD
Thanks @hube2 there were wanted in all other, less, in wp_options
Yes, Something like this
//conection... bla bla bla or
global $wpdb;
$single ="SELECT DISTINCT
ID AS id,
post_title AS title,
(SELECT meta_value FROM ".$wpdb->posts." WHERE post_id = ID AND meta_key = 'images') AS images
FROM
".$wpdb->posts."
WHERE
post_status = 'publish' AND
post_type = 'property'
";
foreach($wpdb->get_results($single, OBJECT) as $rss) {
$img = $rss->images;
$gallery = unserialize( $img );
$images = implode(", ", $galeria);
$photos = "SELECT
meta_value AS photos
FROM
".$wpdb->postmeta."
WHERE
".$wpdb->postmeta.".meta_key = '_wp_attached_file' AND
".$wpdb->postmeta.".post_id IN($imagens)
";
foreach($wpdb->get_results($photos, OBJECT) as $rss) {
echo $rss->photos; // 2016/01/photo.jpg
}
}
If it was inside of wordpress would use their own functions of ACF, but i need to pull these images inside of an xml file to be shown in another location that does not use wordpress.
@hube2 I appreciate you have lost time trying to help me, but for now we have no solution:(
Thanks for reply @hube2
No, I’m using select manual because I’m not inside of wordpress so you can use get_post_meta()
Something like this
//conection... bla bla bla or
global $wpdb;
$single ="SELECT DISTINCT
ID AS id,
post_title AS title,
(SELECT meta_value FROM ".$wpdb->posts." WHERE post_id = ID AND meta_key = 'images') AS images
FROM
".$wpdb->posts."
WHERE
post_status = 'publish' AND
post_type = 'property'
";
foreach($wpdb->get_results($single, OBJECT) as $rss) {
echo $rss->images; // is array serealized, how extract?
}
I wanted to pull all the images from the Gallery, could be perfectly for full url, Yes
Solved! I use switch_to_blog();
global $wpdb;
$result_sql .= "
SELECT ID AS id
";
switch_to_blog(9);
foreach($wpdb->get_results($result_sql, OBJECT) as $rss) {
$map = get_post_meta($rss->id, 'gmap', true);
$map["lat"];
$map["lng"];
} restore_current_blog();
@demo38 Man, u save me. Thank you very much! Worked perfectly for me, just not understand why Elliot codes do not work. Ex: $value['display_name']
@demo38 Thanks for reply.
Probably for my bad english you don’t understand
I have a repeater field with name “agenda”, in it, i have a sub field “user”, in which case it is a relationship user
Look: https://uploaddeimagens.com.br/imagens/repeater-jpg
@elliot and if the field to pull the user is a sub field? How would this array? I tried several times, but it returns only the first letter of the field $values = get_sub_field('relationship_user');
This:
$values = get_field('user');
if($values)
{
echo '<ul>';
foreach($values as $value)
{
echo '<li>' . $value['display_name'] . '</li>';
}
echo '</ul>';
}
dont work, return first letter of the field
This code by @demo38 work:
$values = get_field('user');
if($values){
$array = array_values($values);
echo $array[5];
Why?
Hmm nice, thanks @elliot!
Ok @elliot, thanks, sorry for being so boring
Hi @elliot, thanks for reply again.
So just a thought.
$images = get_field('gallery-field', $post->ID);
if( $images ):
foreach( $images as $image ):
echo '<li style="text-align:center !important;">';
echo '<a href="'.get_permalink($post->ID).'">';
echo '<img src="'.$image['sizes']['large'].'" alt="'.$img_alt.'" />';
echo '</a>';
echo '</li>';
endforeach;
endif;
This form would be the correct way? For that he pull the first image from the Gallery in multsite?
$image['sizes']['large']
Full script
function imoveisRede() {
global $wpdb;
$blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE blog_id != {$wpdb->blogid} AND site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' order by blog_id", ARRAY_A);
array_unshift($blogs, 1); /*Including parent blog in the array*/
$html = '<div>';
foreach($blogs as $blog) {
switch_to_blog( $blog[ 'blog_id' ] );
$posts = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}posts WHERE post_type='imoveis' AND post_status='publish' ORDER BY RAND() DESC LIMIT 10");
$count = 0;
foreach($posts as $post) {
$galerias = get_field('gallery', $post->ID);
$count++;
if ($count == 4) {
$html .= '<div class="clear"></div>';
}else {
$html .= '<div class="property span3" id="destaques">';
$html .='<div class="image">';
$html .='<div class="content">';
$html .='<a href="'.get_permalink($post->ID).'" title="'.$post->post_title.'"></a>';
$html .='<div class="content">';
$html .='<a href="'.the_permalink().'" title="'.$post->post_title.'"></a>';
if( $galerias ):
foreach( $galerias as $galeria ):
$html .='<li style="text-align:center !important;">';
$html .='<a href="'.get_permalink($post->ID).'" rel="lightbox">
<img src="'.$galeria['sizes']['large'].'" alt="'.$img_alt.'" /></a>';
$html .='</li>';
endforeach;
endif;
}
$html .='</div>';
}
$html .='</div>';
}
}
$html .= '</div>';
return $html;
}
@elliot Thanks for reply!
But dont work for me in multisite:/
I use
$galerias = get_field('gallery', $post->ID);
if( $galerias ):
foreach( $galerias as $galeria ):
$html .='<li style="text-align:center !important;">';
$html .='<a href="'.get_permalink($post->ID).'" rel="lightbox">
<img src="'.$galeria['sizes']['large'].'" alt="'.$img_alt.'" /></a>';
$html .='</li>';
endforeach;
endif;
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.