Solved

Check if custom field is set

Posted on 2010-09-23
3
527 Views
Last Modified: 2012-05-10
Hi,

I have a few custom fields set in my post area.

Is there a way to test/check if the custom field is blank?

isset?
0
Comment
Question by:UltraFlux
3 Comments
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 33747580
What is the function of the custom field?
Is it a text area?
Is it an image?

You should be able to go to the post in the WP admin panel to check if the custom field has any content.
0
 

Author Comment

by:UltraFlux
ID: 33747610
I want to test the custom field before displaying on the website (not admin)

ex:
Custom Fields
price-new
price-sale
style

None of these fields are required. If one is blank I simply do not want it to show on the website.

ex:

Price New: $340
Price Sale: $250
Style: New

If "price-new" is not set website should not display "Price New: $340"

Basically I just need to test if the custom field is either set or empty...
0
 
LVL 14

Accepted Solution

by:
Dzynit earned 500 total points
ID: 33748296
      if (get_post_meta(x, 'price-new', true) != '') {
            echo (get_post_meta(x, 'price-new', true));
// or do what you want with the custom field info
        }

Where:
x = your post id number the custom field is on

0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Like there are many different versions of Wordpress, there are also a handful of related side projects WordPress users should be familiar with.   All of these projects are open source and GPL licensed, which means there are few restrictions to us…
Do you think that WordPress is just for blogs?  Think again!  WordPress is really a fantastic all around platform that you can use to develop websites on.  Integrated into its basic functionality is the ability to create pages using your choice of a…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

773 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