After banging away on various solutions, I finally guessed that simply rewriting the array could solve it. Also found some better methods for getting the ALT and TITLE values.
Here’s my code for responsive SEO images with ALT and TITLE tags!
<?php
$image = get_sub_field('photo') ;
$size = '2048x2048';
$alt = get_post_meta($image, '_wp_attachment_image_alt', TRUE);
$img_title = get_the_title($image);
;?>
<?php if( $image ) {
echo wp_get_attachment_image( $image, $size, array('alt'=>$alt), array('title'=>$img_title));
};
?>
Here’s the error it kicks back:
Warning: Trying to access array offset on value of type int in...
If I remove:
$alt = $image['alt'];
$title = $image['title'];
Then everything works… but I don’t get those tags written in of course.
Hey @hube2 finally had a chance to test this. Unfortunately not working for me. Tried with both ID and URL (since you mentioned both in the replies) and also assumed I’d need:
$image_url = get_field('image');
…at the start, so as to include the ACF field. Also assumed that the $image_tag bit was WP native based on how you described it, so not sure what I’m missing.
Ahhh, I think you just explained the inconsistency I’d seen with this. (Hadn’t thought about it in great depth, but seems obvious now that you mention it.)
I have lots of multisites with ACF and this inability to update from the sub-site is a bit irritating. Hope that some effort can be put into resolving this.
Quite frustrating that there’s no way to migrate any ACF based content without either cloning the entire site or using a $300 plugin. Massive design flaw IMHO.
If you’re able to pass this on to the dev team @hube2 that would be great. (Or I can submit a request if that’s not possible.)
No longer relevant so guess this can be ignored since it can’t be deleted.
Been over a week… maybe I should submit this as a regular support ticket?
Thanks @hube2 .
Any tips about where in the DB to look? I remember trying to find ACF fields in the past and got lost looking, also in the documentation.
Maybe this helps… after another round of testing (with debugging turned on) I see these errors:
[08-Sep-2021 13:57:35 UTC] PHP Notice: Trying to get property ‘ID’ of non-object in /www/htdocs/w01a2ea9/sanktoberholz.de/wp-includes/class-wp-query.php on line 4044
[08-Sep-2021 13:57:35 UTC] PHP Notice: Trying to get property ‘post_title’ of non-object in /www/htdocs/w01a2ea9/sanktoberholz.de/wp-includes/class-wp-query.php on line 4046
[08-Sep-2021 13:57:35 UTC] PHP Notice: Trying to get property ‘post_name’ of non-object in /www/htdocs/w01a2ea9/sanktoberholz.de/wp-includes/class-wp-query.php on line 4048
Looking at class-wp-query.php this appears (to my limited understanding) to be the code referenced when making queries in template files. Could this help explain why the post sort of “disappears” to the post query, although it is still visible (and marked published in the backend)?
When a new post is created doing the sync, what happens?
First round is that it creates a draft, which is normal for the plugin.
When an existing post is updated and fields that did not have values are populated, what happens?
I can see the new text when viewing the post in the back end, but it does not become visible on the front-end until manually clicking publish.
When an existing post is updated and fields that did not have values are populated, what happens?
Same as above.
What type of fields are they?
Text and text area. Not sub-fields.
Just did another test… a post listed as being published:
https://sanktoberholz.de/wp-content/uploads/2021/09/Screen-Shot-2021-09-06-at-4.24.39-PM.png
And yet isn’t visible via post query until I hit Update again. Here’s the post query that I’m using, which shows a meta query for displaying only those that have been marked as a specific category (in Salesforce, not a WP category) and a checkbox for whether to make the post visible. (Its for a rudimentary inventory management process.)
<?php
$args = array( 'posts_per_page' => -1, 'post_type' => 'assets',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'area',
'value' => '["MITTE"]',
'compare' => '='
),
array(
'key' => 'show_on_website',
'value' => 1,
'compare' => '='
)
)
);
$myposts = get_posts( $args );
if($myposts):
foreach ( $myposts as $post ) : setup_postdata( $post );
?>
Excellent! That really helps. Wouldn’t have guessed that it worked this way and was critical to being able to do a database search, since the standard wordpress search (in posts or custom posts) can’t see into the data in your fields.
Would be LOVELY if there was an admin tool for this. 😉
Screenshot attached to anyone looking at this in the future:
Revisiting this topic, as I’m working on another project where I have to find specific data in ACF fields.
So I have a wysiwyg field with a key named field_59c990d0410b8. When using phpmyadmin, all I can find is one record for the settings for that field, not the actual content.
Is the content stored somewhere else? In post_content perhaps?
Are there any guides for doing searches on content entered into ACF? I couldn’t find anything, just lots of highly specific questions. So might be helpful to have a guide explaining this, since ACF content is not searchable using wordpress itself.
Anyone looking at old posts or should I submit a new one on the same issue?
Have the same issue and tried the code above, but its not working. Is ‘shop’ the page slug? I also tried the ID number but that didn’t work either.
<?php $page_id = wc_get_page_id( 'shop' );
$your_field = get_field( 'marquee', $page_id ); ?>
Found a super simple fix… since John thought the POST ID was getting lost with all of the switch to blogs, it occurred to me to simply add the post ID via this method:
https://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/
SOLVED!
Hi John, if by “before and after” you mean that I should use this code before the first switch to blog and then after the last one, then that’s what I’ve done here:
https://consulting.sanktoberholz.de/careers/
The first ID is 256 which is the page linked above. The ID 277 is from the Coffee Job Berlin post which is the last post being pulled in on the right hand side of the page. So it would appear that my code for getting posts from three different subdomains (thats the coworking, consulting and coffee job berlin links on the right hand side) is not fully resetting back to the current site?
Confused by your note “ACF will be using the current post ID here”. Everything I read said that switchtoblog is for getting the SITE ID, not post ID. And that restoreblog is for switching back to the SITE ID where the current page is.
Very much appreciate your insights!
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.