![]() |
PHP Help Needed Can anyone help with this PHP problem $dispnosidebar = get_option('it_disp_noside_bar'); The variable above gets the values I need from the options page in wordpress. The problem I am having is getting the variable/values into the code below where the 2,9 is. if ($dispsidebar == "Left" && in_array( $post->ID, array(2,9))) { ?> Thanks Andrew Black |
Re: PHP Help Needed Maybe you could post a little more of what you're doing, Andrew? Or at least explain a little... The section where the 2,9 is is testing that the post id is either 2 or 9. Are you wanting to add a third test for the new option? |
Re: PHP Help Needed Quote:
Thanks for the reply The bit of code that is 2,9 I need to replace with something that puts the contents of the variable $dispnosidebar there instead, the variable will contain the numbers for the posts/pages that I don't want the sidebar displayed on eg: if ($dispsidebar == "Left" && in_array( $post->ID, array(echo $dispnosidebar))) { ?> But that dosen't work I think the code needs to be different but not sure what Thanks Andrew Black |
Re: PHP Help Needed i don't follow you 100%, but how about this code snippet: PHP Code: |
Re: PHP Help Needed Quote:
The code I gave in the OP already works, I just need to replace the 2,9 with the values from the $dispnosidebar variable Andrew Black |
Re: PHP Help Needed All right. You're going to make me get complicated here. I'm assuming that your option contains a string from a form text input or textarea, containing numbers separated by commas. If that's not what's happening, none of the following will do you any good... The option value isn't usable as-is. That is, it contains a string of characters, no different than a sentence. You have to get the number values out somehow before you can use them. You can't just stuff them into a function as you're trying to do. SO - split the string on the commas. The following splits the string by any amount of commas and space characters, including tabs and returns/linefeeds: $dispnosidebar_arr = preg_split( "/[\s,]+/", $dispnosidebar ); NOW you have an array you can insert into your test: if ( $dispsidebar == "Left" && in_array( $post->ID, $dispnosidebar_arr ) ) { Note that you're not going to want to use this, by itself, on any kind of production plugin or theme as the input ( the value of the option ) isn't sanitized or verified at all. |
Re: PHP Help Needed Hi Steve Thanks, that was what I needed What is the issue with the option value not being sanitized or verified? Thanks again Andrew Black |
Re: PHP Help Needed Quote:
Quote:
For instance, what if the user separated the list with semi-colons instead of commas? Or a slash, or even just a space? What if they put a word in there instead of a number character? What if they left it blank? What if they used two commas in a row? |
| All times are GMT -6. The time now is 02:50 AM. |