That does help, thank you John. I tend to overthink image sizes and end up in a tailspin. I’m going to work on simplifying the process.
Keep up the awesome support. I’ve read quite a few of your answers on here and it’s been a great help.
Ah… I think you may have solved it.
I only have two fields (hero_image
and thumbnail_image
). These are set to appear on all pages and posts including custom post types.
I’ve just looked in my header.php
file and look at what I found:
<?php
// Get post ID
$post_id = get_queried_object_id();
// Hero image
$hero = get_field('hero_image', $post_id);
$hero_url = wp_get_attachment_url( get_field('hero_image', $post_id), 'hero');
?>
<?php if ( is_single() || is_archive() ): ?>
<header id="masthead" class="site-header">
<?php else: ?>
<header id="masthead" <?php if ($hero) { echo 'class="site-header has-background" style="background:url('.$hero_url.')"'; } else { echo 'class="site-header"'; } ?>>
<?php endif; ?>
I’ve renamed $post_id
in header.php to $post_id_outside_loop
. I’ve then used this variable via single.php as it’s also outside the loop. This has solved the issue.
For anyone that stumbles across this, see this post for more info.
I think I need to rethink my images sizes. Back to the drawing board. Thank you for your help.
I don’t have any that match 1366×400, but one that does come close. Here are all my sizes:
add_image_size( 'carousel', 1366, 500, true ); // Upload @ 2732px by 1000px for @2x
add_image_size( 'hero', 1366, 400, true ); // Upload using carousel dimensions or @ 2732px by 800px for @2x if the image is too cropped
add_image_size( 'hero-small', 768, 400, true ); // Upload using carousel dimensions or @ 1536px by 800px for @2x
add_image_size( 'large-square', 424, 368, true ); // Upload @ 848px by 736px for @2x
add_image_size( 'medium-square', 289, 256, true ); // Upload @ 578px by 512px for @2x
add_image_size( 'small-square', 215, 170, true ); // Upload @ 430px by 340px for @2x
add_image_size( 'diagram', 650 ); // Upload @ 1300px by any height for @2x
add_image_size( 'full-width', 920 ); // Upload @ 1840px by any height for @2x
add_image_size( 'full-width-cropped', 920, 337, true ); // Upload using full-width dimensions or @ 1840px by 674px for @2x if the image is too cropped
add_image_size( 'half', 436 ); // Upload @ 872px by any height for @2x
add_image_size( 'third', 275 ); // Upload @ 550px by any height for @2x
add_image_size( 'quarter', 195 ); // Upload @ 390px by any height for @2x
I appreciate this question is out of scope, so no worries if you can’t help any further.
Yes, it’s very weird. var_dump($image);
returns int(791)
.
Okay, thanks John.
It’s strange, my function size for hero is as follows:
add_image_size( 'hero', 1366, 400, true );
I’m uploading at 2732px by 800px to account for @2x images. This works across all other image fields (which are smaller).
I’ll do some further digging.
I got a good answer here 🙂 http://wordpress.stackexchange.com/questions/142173/migrating-data-from-acf-to-wordpress-custom-meta-boxes
You’re awesome!
I need to use a special loop to get pagination working with custom post types.
I used this method: http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-another-page and it worked perfectly.
Thank you for pointing me in the right direction.
WordPress developers would quit without your plugin.
Keep up the good work!
S
Hey Elliot. Thank you for your reply. I’ve received the following output after implementing your code:
bool(false)
Looking forward to your feedback.
S
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.