Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7656331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:44:18+00:00 2026-05-31T12:44:18+00:00

I have a custom WordPress panel for my posts which I am referencing with

  • 0

I have a custom WordPress panel for my posts which I am referencing with this

$service = get_post_meta($post->ID, 'service', true);

I’m trying to insert some HTML that says:

if ($service == 1) {
  echo "Water Damage";
}
if ($service == 2) {
  echo "Fire Damage";
}

and so on. This part is not working. If I simply print the results of $service, that will display the appropriate numerical value, but I can’t get the above to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:44:20+00:00Added an answer on May 31, 2026 at 12:44 pm

    If i’m right on this, the problem is that you are addressing $service as an int.

    Have a look in the codex (http://codex.wordpress.org/Function_Reference/get_post_meta) , and you’ll see that if the third Parameter is false it’ll return an array of values, and if it’s true (like in you case) it’ll returns a string.

    In the example above you where trying to compare a string to an int. try to do this instead:

    if($service == '1'){
       echo "Water Damage";
    }elseif($service == '2'){
       echo "Fire Damage";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a similar problem with this ( https://wordpress.stackexchange.com/questions/9593/custom-post-type-archive-with-pagination ) and can't really figure
I have a custom posttype in Wordpress 3. I would like to every post
I have 2 custom fields in my WordPress system when creating new posts. One
I have a custom search engine on a non-wordpress page. This search engine searches
I have made a custom loop in WordPress and for some reason, the date
I have a custom field in WordPress called thumb-url which contains the exact location
Have created a custom navigation menu in wordpress that has some pages and some
I have setup a custom Post Type in WordPress and have a question. How
I have a problem regarding a JSON string grabbed from WordPress custom post meta.
I have a class that uses 5.3 feature anonymous function ( https://github.com/JeffreyWay/Easy-WordPress-Custom-Post-Types/blob/master/jw_custom_posts.php ), but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.