This this link out:
http://www.wpbeginner.com/wp-tutorials/wordpress-custom-fields-101-tips-tricks-and-hacks/
and scroll down until “Using Custom Fields with Conditional Statement”.
Thanks,
But it doesn’t show me how to check for values. I have no problem showing a custom field with a key name. The problem I have is that I have 1 key e.g., CAR and CAR has 3 values 1, 2, 3 (3 options), so I need something like this:
If custom field is CAR with value of 1 then “do this”
If custom field is CAR with value of 2 then “do this”
If custom field is CAR with value of 3 then “do this”
Yes it does, for example this is one of the sample code from that link:
$author = get_post_meta( $post->ID, 'guest-author', true );
if ( $author ) $name = $author;
You just have to use get_post_meta function:
http://codex.wordpress.org/Function_Reference/get_post_meta
In your case, will probably look something like
$CAR = get_post_meta( $post->ID, 'car', true );
if ( $CAR == 1 ) {
...do something ...
}
elseif ( $CAR == 2 ) {
...do another thing...
}
Hi,
Thank you again, from the previous link to the codex page I was able to build this:
<?php $key_1_value = get_post_meta($post->ID, 'wpcf-huge-image', true); ?>
<?php if($key_1_value != '1') { ?>
hello 1
<?php } elseif($key_1_value != '2') { ?>
hello 2
<?php } ?>
To create a custom field I am using the Types plugin and I set option #1 with the value of ‘1’ and option #2 with the value ‘2’ and you can see in the $key_1_value variable above and it works somehow, the problem I am having now is that it works backwards. When I set from the editor the option #1 it display “hello 2” and when I set the option #2 it displays “hello 1”.
Can you figure out what I am doing wrong?
Thank you so much.
PS: I am still new writing conditional statements.
Thank you, it worked like a charm!
But this is my question how did you figured it out? I am interesting on learning, do you know some online resources I can use besides Codex?
Thanks again.
I am programmer, so was able to find it at a glance. The best resource is actually Google, when searching for key words, enclose it with quotes like:
“wordpress bla bla bla”
Because there is no one stop resource available on the internet. And Youtube.com is also a very good resource for video tutors.
You are welcome, have a nice day!