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 - 1 through 15 (of 32 total)
  • Author
    Posts
  • #45522
    asiek
    Participant

    I followed [this tutorial.](http://tatiyants.com/how-to-use-wordpress-custom-post-types-to-add-events-to-your-site/http://tatiyants.com/how-to-use-wordpress-custom-post-types-to-add-events-to-your-site/”)

    Added a custom textarea to the meta box for “Events” the information is displayed on my events page but my issue now is that when there is no text inside of the textarea the label “INFO” is still visible. I’d like to remove the label if no information has been added.

    Here is the code for the custom text area//

    $ret = $ret . '

    ';

    and here is the code I used for the html within the function//

    $ret .= ‘[div class=”event-section”]’;
    $event_info = get_post_meta($post->ID, ‘event_info’, true);
    if (!empty($event_info)) {
    $ret .= ‘INFO:   ‘ . $event_info . ‘‘ ;
    } $ret .= ‘[/div]’;

    Any ideas?
    Please help…
    Thanks in advance!

    #138666
    chrisburton
    Participant

    My WordPress setup was similar. I changed yours to what mine looked like which worked for me.

    $event_info = get_post_meta($post->ID, ‘event_info’, true);
    if(!empty($event_info)): ?>
    INFO: 

    #138668
    asiek
    Participant

    @chrisburton Sorry I forgot to mention this code was inside of my functions.php file.

    #138669
    chrisburton
    Participant

    @Keilowe Why wouldn’t you put it in your template file?

    #138671
    asiek
    Participant

    @chrisburton The tutorial I linked to is an Events CPT, and inside of it, the author created a shortcode that holds the date, location, ticket price and event information.

    So on my wordpress Events page all I have to add add this short code//

    [events daterange=”current”]

    #138674
    chrisburton
    Participant

    @keilowe I don’t know if this will help but try removing the space between `if (…`

    #138673
    asiek
    Participant

    @chrisburton :( No it didn’t work…I appreciate your effort to help me!

    #138676
    chrisburton
    Participant

    @keilowe Try this

    $ret .= ‘[div class=”event-section”]’;
    $event_info = get_post_meta($post->ID, ‘event_info’, true);
    if($event_info != ”) {
    $ret .= ‘INFO:   ‘ . $event_info . ‘‘ ;
    } $ret .= ‘[/div]’;

    #138678
    asiek
    Participant

    @chrisburton Nope :/
    Would it help to post the section of my CPT?

    #138750
    asiek
    Participant

    Anyone?

    #138764
    asiek
    Participant
    #138768
    asiek
    Participant

    @chrisburton I placed my Shortcode function inside of [this pastebin.](http://pastebin.com/LkK67GXdhttp://pastebin.com/LkK67GXd”)

    If you wanted to give it a looksie?

    #138771
    chrisburton
    Participant

    This is a bit over my head. When it comes to PHP, I only know what I’ve had to do for my own website. I’ve never dealt with shortcodes when I used WordPress for my CMS. Maybe @traq could chime in.

    #138773
    asiek
    Participant

    @chrisburton Okay :) Thank you for trying to help though!

    #138778
    __
    Participant

    I assume this is lines 134-137…?

    On the surface, I don’t see any reason why this wouldn’t work as desired. No offense to you (or anyone), but I have a strong dislike for WP behind-the-scenes, and the “shortcode” and “functions.php” models are two of the main reasons why. : )

    `get_post_meta` (with `$single=true`) is supposed to return an empty string if it finds nothing.

    /* snip */
    // on|around line 134:
    $event_info = get_post_meta($post->ID, ‘event_info’, true);

    // add this right here
    var_dump( $event_info ); exit;

    // tell me what it shows you

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