Solved

Check if custom field is set

Posted on 2010-09-23
3
526 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Link to post behind image slider 1 52
logo disappears on cell phones 5 57
WordPress - Published Webpage missing posts 4 46
Wordpress errors showing up, hacked? 4 12
Transferring a wordpress site from a host or local dev server to another host can be a pain. So I've included my steps on how I have accomplished this task. Steps include an assumption that you have Cpanel access or Ftp access.. If you do not hav…
WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now