WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Events Manager] Using Search with this plugin

[Plugin: Events Manager] Using Search with this plugin

Viewing 4 replies - 1 through 4 (of 4 total)
  • Daniel Payne
    Participant

    @djepayne

    Instead of the Codex approach I just updated my search.php file and placed the following code above the loop:

    mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
    @mysql_select_db(DB_NAME) or die( "Unable to select database");
    $table = $table_prefix."em_events";
    $s = $_REQUEST['s']; // The search key words
    $found_event = false;
    
    $query = "SELECT * FROM $table WHERE (event_name LIKE '%".$s."%') OR
    (event_notes LIKE '%".$s."%') ORDER BY event_start_date";
    $result = mysql_query($query) or die(mysql_error());
    
    while($row = mysql_fetch_array($result)) { // Found some matches
    	print "<h2><a href='".get_bloginfo('url')."/events/?event_id=".$row['event_id']."'>".$row['event_name']."</a> ".$row['event_start_date']."</h2>";
    	print substr($row['event_notes'],0,250)."[...]";
    	print "<div style='clear:both;'></div>";
    	$found_event = true;
    }
    Plugin Author Marcus
    Participant

    @netweblogic

    @djepayne

    Thanks for the link, will look into that!

    Daniel Payne
    Participant

    @djepayne

    Based on feedback I’ve updated the PHP code to use more WordPress built-in functions:

    $table = $wpdb->prefix."em_events";
    $s = mysql_real_escape_string($_REQUEST['s']); // The search key words
    
    $found_event = false;
    
    $query = "SELECT * FROM $table WHERE (event_name LIKE '%".$s."%') OR
    (event_notes LIKE '%".$s."%') ORDER BY event_start_date";
    $events = $wpdb->get_results ( $query, ARRAY_A );
    foreach ($events as $row) {
            print "<h2><a href='".get_bloginfo('url')."/events/?event_id=".$row['event_id']."'>".$row['event_name']."</a> ".$row['event_start_date']."</h2>";
            print substr($row['event_notes'],0,250)."[...]";
            print "<div style='clear:both;'></div>";
            $found_event = true;
    }
    Plugin Author Marcus
    Participant

    @netweblogic

    we’ll add a search feature eventually that’ll shave off a few lines of code here.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Events Manager] Using Search with this plugin’ is closed to new replies.