WordPress.org

Support

Support » Plugins and Hacks » Expired plugin Events Manager Extended, use Events Made Easy » [Resolved] [Plugin: Events Manager Extended] How to search Events?

[Resolved] [Plugin: Events Manager Extended] How to search Events?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Franky

    @liedekef

    hi, thanks for the tip. This might indeed work, and I need to play with that. Let me test this out. Also: could you post this as a feature request on http://www.e-dynamics.be/bbpress ?

    Instead of the Codex approach I just updated the search.php file in my theme by adding the following PHP 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;
    }

    FYI – this works with the Events Manager plugin, not tested with Events Manager Extended plugin.

    Plugin Author Franky

    @liedekef

    Well, I just checked the Codex approach and it would be hard to get it to work. The reason being that it needs to be able to left join with the posts table, and we have no real relation between the events and the posts. Your code works of course, but needs some tuning. This is better (don’t reconnect to the db yourself, wp has this covered):

    $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 Franky

    @liedekef

    And btw: yes, it works also for EME 🙂
    And to make it a bit more secure, escape the query string:

    $s = mysql_real_escape_string($_REQUEST[‘s’]); // The search key words

    Thanks for the feedback. I’m still learning WordPress and come from a pure custom PHP and MySQL environment.

    There’s such a steep learning curve with so many WordPress functions.

    Plugin Author Franky

    @liedekef

    No prob, I already posted this code as a little howto on my forum. So I need to thank you 🙂

    @liedekef, could you post a link to your howto? Thanks!

    Plugin Author Franky

    @liedekef

    Hi,

    I have a problem using this search code.

    Some searches work and some don’t.

    For example, if the title of the event is “Building computer networks” and I type:
    Network -> It shows the right result
    Networks -> It shows no results.

    I have an event which titles include these 2 keywords: “Engineering” and “Aviation”
    If I type:
    Aviation -> No results
    Engineering -> It shows the right results

    It’s driving me mad and my client as well…

    All right… I found my mistake!!

    I put the code within the “If post ()” code… so if no pages/posts were including the word, no results would come up…

    I hope this can help somebody else who did the same mistake.

    But now, the problem is that if the keywords doesn’t come up in any pages but in some events, we will still have the message “Nothing Found” under the events, which is a bit stupid.

    Is there anyway to change “If post” by “if results”?

    Plugin Author Franky

    @liedekef

    Check the second example again, and use “$found_event = true;” and “if (!$found_event)” where appropriate.

    Hello.
    I’m trying to set up the search according to this thread, but I’m not used to PHP coding, so I’m using the Suffusion theme.
    Unfortunately, the code isn’t even close to working, and I’m wondering if something has changed with the plugin itself and affected this code.
    Right now, my search.php file is looking like this:

    <?php
    /**
     * Search results, can be set up to show either excerpts or full contents
     *
     * @package Suffusion
     * @subpackage Templates
     */
    
    global $suffusion_unified_options;
    foreach ($suffusion_unified_options as $id => $value) {
    	$$id = $value;
    }
    
    get_header(); ?>
    
        <div id="main-col">
    <?php suffusion_before_begin_content(); ?>
    
          <div id="content" class="hfeed">
    <?php
    
    if ($suf_search_excerpt == 'list') {
    	get_template_part('layouts/layout-list');
    }
    else if ($suf_search_excerpt == 'tiles') {
    	suffusion_after_begin_content();
    	get_template_part('layouts/layout-tiles');
    }
    else {
    	suffusion_after_begin_content();
    	get_template_part('layouts/layout-blog');
    }
    ?>
    
    <?php
    $table = $wpdb->prefix."dbem_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 eme_event_url($row);
            print substr($row['event_notes'],0,250)."[...]";
            $found_event = true;
    }
    
    ?>
    
      <?php if (have_posts()) : ?>
    
      <?php endif; ?>
          </div><!-- content -->
        </div><!-- main col -->
    <?php get_footer(); ?>

    The usual search results are showing up, but the events aren’t.
    Can someone please give me a hint on what to do?

    Plugin Author Franky

    @liedekef

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Resolved] [Plugin: Events Manager Extended] How to search Events?’ is closed to new replies.
Skip to toolbar