Home › Forums › Back End › [WORDPRESS] Remove div IF textarea is empty for Events Post Type Function
- This topic is empty.
-
AuthorPosts
-
June 14, 2013 at 10:06 pm #138780asiekParticipant
@traq Yes I apologize for not pointing out the location of the issue.
I’m not a PHP guru lol so I’m lost.
BUT I did add
var_dump( $event_info ); exit;
above these lines //
if(!empty($event_info)) {
$ret .= ‘INFO: ‘ . $event_info . ‘‘ ;
}and I didn’t necessarily get an error page, but I got some sort of message in the content area of my template//
string(33) “Extra Details “
June 14, 2013 at 10:29 pm #138781__Participant>`string(33) “Extra Details “`
It says “33”? Is “Extra Details ” the entire text it returns?
Does the pastebin you posted contain **all** the code you’re using?
In any case, that means `$event_info` is not empty – so the condition is true, and “INFO” will be added. Is this an event where you expect the event info to be empty?
If not, if you can, try running this with an event where you expect `$event_info` to be empty.
June 14, 2013 at 10:38 pm #138782asiekParticipant@traq would you like me to post the Whole entire CPT + Shortcode Function ?
Because the pastebin only includes the Shortcode section…I basically want the “INFO” text etc to be removed IF the Event has no extra information inserted into the textarea I created…
If it helps I’ve taken [a screenshot of the issue](http://i43.tinypic.com/2s7xbuw.png “http://i43.tinypic.com/2s7xbuw.png”).
June 14, 2013 at 10:48 pm #138783__ParticipantNo, I understand the issue; I’m just trying to understand where the problem is coming from. The code you posted seems like it should be producing the desired result –
if your `if( ! empty( $event_info ) )` condition is _always true_, I’d like to backtrack and see what might be causing `$event_info` to _never be empty_.
Yes, it would be helpful to see _everything_ you wrote.
In particular, how did you define the fields for your custom post type?
June 14, 2013 at 11:01 pm #138785asiekParticipant@traq Here is the ENTIRE Events CPT http://pastebin.com/4DA0AFQw
:)
June 14, 2013 at 11:10 pm #138786June 14, 2013 at 11:13 pm #138787chrisburtonParticipantAdrian, what if it was outputting whitespace even if she didn’t add anything to the textarea? That would also make it run true.
June 14, 2013 at 11:28 pm #138788__Participantalright… what I’m looking for is something that might add the value “Extra Details” as a default value for your `event_info` column. I’m not seeing anything – that phrase doesn’t appear anywhere in the code you posted. Any ideas?
>Adrian, what if it was outputting whitespace even if she didn’t add anything to the textarea? That would also make it run true.
Yes, it would. But WP says it should return “an **empty** string” in that instance… unless whitespace (or something else, like a javascript “placeholder” value, for example) is actually being added to the form field somehow.
@Keilowe, when you ran my code the first time, did you expect `$event_info` to be empty?Also,
>It says “33”? Is “Extra Details ” the entire text it returns?June 14, 2013 at 11:41 pm #138790asiekParticipant@traq “INFO” is just text I added as a label.
$ret .= ‘
‘;
$event_info = get_post_meta($post->ID, ‘event_info’, true);
if ( ! empty($event_info)) {
$ret .= ‘INFO: ‘ . $event_info . ‘‘ ;
}
$ret .= ‘‘;
Even if $event_info is empty the text “INFO” still appears.
June 14, 2013 at 11:44 pm #138791asiekParticipant@traq when I use the line of code you posted
$ret .= ‘
‘;
$event_info = get_post_meta($post->ID, ‘event_info’, true);
var_dump( $event_info ); exit;
if ( ! empty($event_info)) {
$ret .= ‘INFO: ‘ . $event_info . ‘‘ ;
}
$ret .= ‘‘;
[This happens](http://i39.tinypic.com/2yvrzok.png “http://i39.tinypic.com/2yvrzok.png”). It removes my container and all the events and just displays the
> “string(33) “Extra Details “”
June 14, 2013 at 11:54 pm #138792asiekParticipant@traq @chrisburton I FIXED IT!
June 14, 2013 at 11:57 pm #138793__Participant>Even if $event_info is empty the text “INFO” still appears.
What I’m getting at is that, if you see “INFO”, that means that `$event_info` was _not_ empty, even though you expected it to be. `var_dump` lets us see the value that `$event_info` contained: a string, 33 characters long. Since we only see 15 characters displayed, I’m assuming the other 18 are HTML markup or whitespace of some sort.
Try viewing the HTML source of your webpage, and look for the full value after `string(33)`. Copy+paste it, please.
>This happens. It removes my container and all the events …
Right, because I had you do `exit;`. It’s not a solution, it’s a test. Because we exit the script, then the value we dumped should be the _last_ bit of text on your webpage (easier to find that way).
June 14, 2013 at 11:58 pm #138794__Participant>>@traq @chrisburton I FIXED IT!
…great! What was going on?
June 14, 2013 at 11:59 pm #138795asiekParticipant@traq @chrisburton I used a test line that the author of the tutorial I followed recommended to me.
The test line is//$ret = $ret . ‘INFO: {‘ . $event_info . ‘}‘ ;
By adding that code I could see if there was a space added into the textarea but no actual text. AND THERE WAS IN FACT A FEW SPACES!
So I edited the event with the empty Info, deleted the spaces and now…what do you know!!! The label “INFO” disappeared!!!!
I find that ridiculous though :/ A Few spaces could make such a difference.
Is there any possible way for WP to only display the INFO label if actual text was inserted?Does that question even make sense?
I really apologize for wasting your time :/
Such a small mistake could cause so much confusion!June 15, 2013 at 12:32 am #138796 -
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.