Solved

Wordpress Custom Fields from a Post

Posted on 2014-01-20
3
343 Views
Last Modified: 2014-01-20
On my website, some pages have a lower third section that I want to make editable and separate from the page itself.

I created a category called "lower-thirds" and created a new post(#38) with 2 custom fields.

Here's my code:

<?php
$post_id = 38;
$queried_post = get_post($post_id);
?>
                            
<div class="bottom_third_img">
<img src="<?php get_post_meta($post_id->ID,'bottom_third_head',true);?>" width="673" height="38">
</div>

<div class="bottom_third_txt">
        <div class="bottom_third_info">
           <h2><?php echo $queried_post->post_title; ?></h2>
           <p><?php echo $queried_post->post_content; ?></p>
</div>
<div class="bottom_third_picture">
            <img src="<?php get_post_meta($post_id->ID,'bottom_third_image',true);?>" alt="Alt Text Here..." width="161" height="100">                                
</div>
<div style="clear:both;"></div>
</div>

Open in new window


The custom field values are saved for post #38, but the img src tag is blank when I run this code.

The text and header is working as it is supposed to.

Any suggestions?
0
Comment
Question by:slightlyoff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 500 total points
ID: 39795608
You already assigned a post ID.  Try this instead:

<?php
$post_id = 38;
$queried_post = get_post($post_id);
?>
                            
<div class="bottom_third_img">
<img src="<?php get_post_meta($post_id,'bottom_third_head',true);?>" width="673" height="38">
</div>

<div class="bottom_third_txt">
        <div class="bottom_third_info">
           <h2><?php echo $queried_post->post_title; ?></h2>
           <p><?php echo $queried_post->post_content; ?></p>
</div>
<div class="bottom_third_picture">
            <img src="<?php get_post_meta($post_id,'bottom_third_image',true);?>" alt="Alt Text Here..." width="161" height="100">                                
</div>
<div style="clear:both;"></div>
</div> 

Open in new window

0
 
LVL 1

Author Closing Comment

by:slightlyoff
ID: 39795641
Thanks for the help!  I also for to echo it.
0
 
LVL 17

Expert Comment

by:OmniUnlimited
ID: 39795653
Glad to assist.  Let me know if you have any further issues.
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you use a default hosting installation of wordpress with the intention of it being your actual site?  Maybe you’ve installed it as a Blog to your current site and recently converted it to be the main site and do away with the old .htm pages.  An…
How to install BuddyPress on your self-hosted WordPress site It’s been called everything from “social networking in a box” to “Facebook without the terms of service,” but until Feb. 16, BuddyPress was a relatively unknown outside the WordPress MU…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question