Chuck T Posted May 27, 2011 Share Posted May 27, 2011 Hey guys, you'll have to forgive me because i'm an absolute BUM when it comes to php. But i'm trying to make this work. In my header, i'm running this code: <meta property="fb:app_id" content="<?php if (get_option('woo_fb_id') <> "") { echo stripslashes(get_option('woo_fb_id'));} ?>"/> You all probably know what it means. I kinda translate it as if the fb_id text input is filled out, get the text. Right? But What I want it do is... check to see if the fb_id filled out here first: <?php echo get_post_meta($post->ID, appid, true); ?>"/> THEN check to see if that text area is filled out and if so, use the text. However i have no idea how to write that! Any help would be GREATLY appreciated guys! Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/ Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 I'm kind of confused. If you want to check if the fb_id has a value, like you did in your first snippet, than wrap the second snippet with that if statement you use in the first. I think I may be missing something here. Can you perhaps explain a little better. Also, you can use the empty() function rather than checking of the fb_id is not equal to an empty string. For example if (!empty(get_option('woo_fb_id'))) { ... } Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221280 Share on other sites More sharing options...
Chuck T Posted May 27, 2011 Author Share Posted May 27, 2011 Hey Mike! Thanks for the quick response. I was expecting to confuse you, that's what i'm here for. I want the code the check to see if get_post_meta($post->ID, appid has a value first. If it doesn't, then I want it to carry on as usual by using the value in fb_id <?php if (get_option('woo_fb_id') <> "") { echo stripslashes(get_option('woo_fb_id'));} ?> So kinda like - IF <?php echo get_post_meta($post->ID, appid, true); ?>"/> ELSE (get_option('woo_fb_id') <> "") { echo stripslashes(get_option('woo_fb_id')); If that makes any sense Thanks for your help man! Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221289 Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 Oh I see. well if I am interpreting you correctly, you want to echo the get_post_meta($post->ID, appid, true) string if the get_post_meta($post->ID, appid, true) string has a value (IE is not empty), otherwise you want to echo the stripslashes(get_option('woo_fb_id')) string (assuming that the get_option('woo_fb_id') string is not an empty string). Is this interpretation correct? if so you could do something like if (!empty(get_post_meta($post->ID, appid, true)){ echo get_post_meta($post->ID, appid, true); } else if (!empty(get_option('woo_fb_id')) { echo stripslashes(get_option('woo_fb_id')); } Hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221301 Share on other sites More sharing options...
Chuck T Posted May 27, 2011 Author Share Posted May 27, 2011 Thanks for the help Mike. I tried it and it's giving me a Fatal error: Can't use function return value in write context. Here's the code i'm using: <meta property="fb:app_id" content="<?php if (!empty(get_post_meta($post->ID, appid, true)){ echo get_post_meta($post->ID, appid, true); } else if (!empty(get_option('woo_fb_id')) { echo stripslashes(get_option('woo_fb_id')); } ?>"/> I could be doing something complete wrong. Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221317 Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 what line is this error occuring on? What does the function get_post_meta() return? Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221318 Share on other sites More sharing options...
Chuck T Posted May 27, 2011 Author Share Posted May 27, 2011 It's on line 22, which would be this one: content="<?php if (!empty(get_post_meta($post->ID, appid, true)){ get_post_meta is a custom field, if you're familiar with wordpress. So it should be checking to see if the post has an appid, if so then use the value. Otherwise, use the value from fb_id. Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221324 Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 Oh, well you are missing a closing parenthesis on this line if (!empty(get_post_meta($post->ID, appid, true)) it should be if (!empty(get_post_meta($post->ID, appid, true))) my apologies, my above code snippet was incorrect Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221336 Share on other sites More sharing options...
Chuck T Posted May 27, 2011 Author Share Posted May 27, 2011 It's still giving me the same error - am I doomed? :-\ Oh and please PM me your paypal address - i'd love to pay your for your help so far. Thanks man! Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221342 Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 I see. The script must have failed before it got to that syntax error. If you echo out get_post_meta what does it echo? I was under the impression that it returned a string that you wanted to verify, but that doesn't seem to be the case. Sorry, but i'm not very familiar with wordpress, so I'm not really sure what a custom field is. Is there any way you could give more details about this function? Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221344 Share on other sites More sharing options...
Chuck T Posted May 27, 2011 Author Share Posted May 27, 2011 Sure thing. I could try to explain it, but it'll probably confuse you even more . Here is wordpress' definition of custom fields in a language you'd probably understand: http://codex.wordpress.org/Custom_Fields Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221346 Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 Ok. well that function, based on the parameters you are passing, should return a single string containing some key value. The key parameter you passed doesn't have any quotes around it. Perhaps it should be get_post_meta($post->ID, 'appid', true) This is assuming you aren't using a global constant named appid to store the value you wanted to pass into that function. However, theoretically, assuming you dont have a global constant named appid, it should still work (although it would throw a warning if you have error reporting turned on). if that doesn't work, you could try simply comparing the return value to an empty string, like you did in the original post, IE if (get_post_meta($post->ID, 'appid', true) != ""){ ... Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221350 Share on other sites More sharing options...
Chuck T Posted May 27, 2011 Author Share Posted May 27, 2011 Tried it with the quotes - it's still giving me the same error on the same line. Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221353 Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 did you try the second snippet I posted, without using the empty() function Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221358 Share on other sites More sharing options...
Chuck T Posted May 27, 2011 Author Share Posted May 27, 2011 Yup, just tried that one and error moved to line 25. This one: else if (!empty(get_option('woo_fb_id')) { So i'm starting to think that wordpress doesn't like the (!empty things, at all. Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221364 Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 yeah apparently not. Try without the empty, doing what you did in the original post. That's strange. Sorry, as I said, i'm unfamiliar with wordpress so I didn't know it would act that way with the empty function Quote Link to comment https://forums.phpfreaks.com/topic/237662-need-serious-help-with-a-ifelse-statement/#findComment-1221373 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.