Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [WORDPRESS] Remove div IF textarea is empty for Events Post Type Function

  • This topic is empty.
Viewing 15 posts - 16 through 30 (of 32 total)
  • Author
    Posts
  • #138780
    asiek
    Participant

    @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 “

    #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.

    #138782
    asiek
    Participant

    @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.pnghttp://i43.tinypic.com/2s7xbuw.png”).

    #138783
    __
    Participant

    No, 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?

    #138785
    asiek
    Participant

    @traq Here is the ENTIRE Events CPT http://pastebin.com/4DA0AFQw

    :)

    #138786
    asiek
    Participant

    @traq Line 116 should be the location of “Info” textarea…

    #138787
    chrisburton
    Participant

    Adrian, what if it was outputting whitespace even if she didn’t add anything to the textarea? That would also make it run true.

    #138788
    __
    Participant

    alright… 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?

    #138790
    asiek
    Participant

    @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.

    #138791
    asiek
    Participant

    @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.pnghttp://i39.tinypic.com/2yvrzok.png”). It removes my container and all the events and just displays the

    > “string(33) “Extra Details “”

    #138792
    asiek
    Participant

    @traq @chrisburton I FIXED IT!

    #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).

    #138794
    __
    Participant

    >>@traq @chrisburton I FIXED IT!

    …great! What was going on?

    #138795
    asiek
    Participant

    @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!

    #138796
    asiek
    Participant

    @traq Please ignore that last question. What I wanted to achieve is now done so it’s all good. Thank you so much for your time!

Viewing 15 posts - 16 through 30 (of 32 total)
  • The forum ‘Back End’ is closed to new topics and replies.