I am creating Event Builder Plugin. I have created shortcode for displaying name of all events on home page. Now on clicking event name, I want to show description of that event. How to do that in plugin? Below is my code:

function event_display(){?>

<?php global $wpdb;
    $myrows = $wpdb->get_results( "SELECT event_cat_id, event_cat_name FROM tcm_event_category" ); 
    foreach($myrows as $myrow){
        echo "<h3>".$myrow->event_cat_name."</h3>";
        $evetcatid = $myrow->event_cat_id; 
        $myevents = $wpdb->get_results( "SELECT event_id, event_name, event_desc, event_short_desc, event_startDate, event_bookFee FROM tcm_event WHERE event_catt_id=$evetcatid" ); 
        foreach($myevents as $myevent){
            echo "<div class='event' style=''>";
            echo "<p style='width:100%;'><a href='?detail_event_display($myevent->event_id)'>".$myevent->event_name."</a></p>";
            echo "<p style='width:70%;float:left;'>".$myevent->event_short_desc."</p>";
            echo "<p style='width:30%;float:right;'>".$myevent->event_startDate."</p>";
            echo "<p style='width:30%;float:right;'> Rs. ".$myevent->event_bookFee."</p>";
            echo "</div>";
function detail_event_display($eventid){
    echo $eventid;
add_shortcode('events', 'event_display');
  • 1
    What's the code you have tried so far to accomplish what you're after? This isn't really a place to ask for complete solutions. – swissspidy Mar 12 '18 at 18:55
  • I want an idea, how to do that? Like in <a> tag I want to give link with eventID to show description – Rachanat Mar 12 '18 at 18:59
  • 1
    it is not clear what you are actually asking, it would be much better to discuss actual code where people can see what is it that you are doing wrong. there might be many aspects to the question, and as it is now without code it is hard to know which one are you having trouble with – Mark Kaplun Mar 12 '18 at 19:22
  • The answer depends on how you have created the events. Are they in a CPT? As the others have noted, we need a frame of reference to work from, which is usually easiest if you provide your code and a more specific question. – WebElaine Mar 12 '18 at 19:40

While this question needs work, (show us your code, what have you tried, what exactly do you want to do with specifics, ect), my answer would be this:

1) Display the description, but apply display: none via CSS to it's container div to hide it. Then write some javascript for an onclick event to apply display: none to all the descriptions, but remove display: none for the event the user clicked.


2) Include the post (event) ID somewhere as an html ID or a hidden input, then write some javascript onclick event to send this ID to a PHP function via ajax. Have this PHP get the description for that ID, then you place this where ever you want with javascript. This solution requires more work and an understanding of ajax though.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.