WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
Using Search with this plugin (5 posts)

  1. Daniel Payne
    Member
    Posted 3 years ago #

    I'm using this plugin and wanted to know how do I connect the Search feature to the custom database table fields?

    Would the approach written about in the Codex add Search to Event Manager?

    Thanks again.

    http://wordpress.org/extend/plugins/events-manager/

  2. Daniel Payne
    Member
    Posted 3 years ago #

    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;
    }
  3. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 3 years ago #

    @djepayne

    Thanks for the link, will look into that!

  4. Daniel Payne
    Member
    Posted 3 years ago #

    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;
    }
  5. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic