Home › Forums › Back End › [WORDPRESS] Remove div IF textarea is empty for Events Post Type Function
- This topic is empty.
-
AuthorPosts
-
June 13, 2013 at 11:06 pm #45522
asiek
ParticipantI 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 #138666chrisburton
ParticipantMy 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:
June 14, 2013 at 12:46 am #138668asiek
Participant@chrisburton Sorry I forgot to mention this code was inside of my functions.php file.
June 14, 2013 at 12:52 am #138669chrisburton
Participant@Keilowe Why wouldn’t you put it in your template file?
June 14, 2013 at 1:20 am #138671asiek
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”]
June 14, 2013 at 1:39 am #138674chrisburton
Participant@keilowe I don’t know if this will help but try removing the space between `if (…`
June 14, 2013 at 1:46 am #138673asiek
Participant@chrisburton :( No it didn’t work…I appreciate your effort to help me!
June 14, 2013 at 1:53 am #138676chrisburton
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]’;June 14, 2013 at 1:58 am #138678asiek
Participant@chrisburton Nope :/
Would it help to post the section of my CPT?June 14, 2013 at 4:46 pm #138750asiek
ParticipantAnyone?
June 14, 2013 at 6:07 pm #138764asiek
Participant@mcjohnst Here is [the short code function.](http://pastebin.com/LkK67GXd “http://pastebin.com/LkK67GXd”)
June 14, 2013 at 7:03 pm #138768asiek
Participant@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 #138771chrisburton
ParticipantThis 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 #138773asiek
Participant@chrisburton Okay :) Thank you for trying to help though!
June 14, 2013 at 9:53 pm #138778__
ParticipantI 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
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.