[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Check if custom field is set

Posted on 2010-09-23
3
Medium Priority
?
536 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 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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…
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 Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
Suggested Courses

872 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