Retrieve custom field value from a page (not post)
-
y home page has an image which populates via a URL inserted into the custom field I’ve created. My snippet of code is displaying my img tag 3 times, first 2 with no src, (i.e. <img src with=900>), and the 3rd properly. It even eliminats the equals sign and the 2 double quotes. This is the snippet I am referring to:
<main id="home"> <?php query_posts('post_type=page'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <img id="showcase" src="<?php echo get_post_meta($post->ID, 'Main Home Page Image',true); ?>" width="900"> <?php endwhile; ?> <?php else : ?> <h2>Not Found</h2> <?php endif; ?> <?php wp_reset_query(); ?> </main>
When this renders in the browser, I get 2 blank squares and the 3rd is the image I want. Source code when rendered looks like this:
<img id="showcase" src width="900"> <img id="showcase" src width="900"> <img id="showcase" src="https://localhost/wp-content/uploads/2014/04/index.jpg" width="900">
I am simply looking to pull the URL once and have it populate the image. Again, this is coming from a page not a post. Can anyone offer me some insight?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Retrieve custom field value from a page (not post)’ is closed to new replies.