Forums

  • # June 13, 2013 at 11:06 pm

    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!

    # June 13, 2013 at 11:37 pm

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

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

    # June 14, 2013 at 12:46 am

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

    # June 14, 2013 at 12:52 am

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

    # June 14, 2013 at 1:20 am

    @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”]

    # June 14, 2013 at 1:39 am

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

    # June 14, 2013 at 1:46 am

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

    # June 14, 2013 at 1:53 am

    @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]’;

    # June 14, 2013 at 1:58 am

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

    # June 14, 2013 at 4:46 pm

    Anyone?

    # June 14, 2013 at 6:07 pm

    @mcjohnst Here is [the short code function.](http://pastebin.com/LkK67GXd “http://pastebin.com/LkK67GXd”)

    # June 14, 2013 at 7:03 pm

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

    If you wanted to give it a looksie?

    # June 14, 2013 at 7:45 pm

    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.

    # June 14, 2013 at 7:52 pm

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

    __
    # June 14, 2013 at 9:53 pm

    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)

You must be logged in to reply to this topic.

icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag