Solved

Wordpress Custom Fields from a Post

Posted on 2014-01-20
3
335 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
WordPress has made it easy to create scalable sites based on their powerful CMS, but as great as WordPress is, there are some SEO issues that haven’t been addressed out of the box.  Fortunately these problems can be solved with a few plugins.  The f…
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 properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…

696 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