Events Made Easy Forums How do I … Howto: Include your events in the search result

Viewing 33 posts - 1 through 33 (of 33 total)
  • Author
    Posts
  • #42186
    Franky
    Keymaster

    If you want your events to show up in the search result, use this code in your theme search.php (outside the have_posts() loop):

    $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 "<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;
    }

    Of course change the links returned to your liking … and you’ll want to change the rest of the search.php so it doesn’t come complaining that no results have been found (since events aren’t posts).

    This can also work for locations and such as well of course.

    #45119
    Franky
    Keymaster

    Real life example code (see http://www.e-dynamics.be/bbpress/topic.php?id=223#post-1056):

    <?php get_header(); ?>
    <div id="content" class="narrowcolumn">

    <?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 "<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;
    }

    ?>

    <?php if (have_posts()) : ?>
    <h2 class="pagetitle">Suchergebnisse</h2>
    <?php while (have_posts()) : the_post(); ?>
    <div class="post">
    <h2 id="post-<?php the_ID(); ?>"><a>" rel="bookmark" title="Permanenter Link zu <?php the_title(); ?>">
    <?php the_title(); ?>
    </a></h2>
    <p class="meta">
    <span class="timr"><?php the_time('F d, Y') ?></span>
    <span class="user">Von: <?php the_author() ?> </span>
    <span class="catr">Kategorie: <?php the_category(', ') ?></span>
    <?php edit_post_link('Bearbeiten', '<span class="editr">', '</span>'); ?>
    </p>
    <?php the_content('<p class="serif">Lies den rest des Eintrags »</p>'); ?>
    <?php wp_link_pages(array('vorige' => '<p><strong>Pages:</strong> ', 'nachfolgende' => '</p>', 'next_or_number' => 'number')); ?>
    <p class="postmeta">
    <span class="commr"><?php comments_popup_link('Noch keine Kommentare →', 'Kommentar (1)', 'Kommentare (%)'); ?></span>
    </p>
    </div>
    <?php endwhile; ?>
    <div class="navigation">
    <div class="alignleft">
    <?php next_posts_link('← Vorige Artikel') ?>
    </div>
    <div class="alignright">
    <?php previous_posts_link('Nachfolgende Artikel →') ?>
    </div>
    </div>
    <?php else : ?>

    <?php if (!$found_event) { ?>
    <div class="post">
    <h2>Keine Artikel gefunden. Bitte suche mit einem anderen Begriff</h2>
    <p><?php include (TEMPLATEPATH . '/searchform.php'); ?></p>
    </div>
    <?php } ?>

    <?php endif; ?>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    #45120
    Anonymous
    Inactive

    Hi,

    this works fine, but the links in search results are not working correctly.

    Example: My site http://hki.halvathuvit.com – when you make a search with term “kaupunkitanssit” you will get full list of results with the term. But the links are like “http://hki.halvathuvit.com/events/event_id=80&#8221; and because I use pretty URL’s, clicking the link gives me 404-page. The correct link should be “http://hki.halvathuvit.com/events/2011-08-31/&#8221;. That URL I get when I navigate through calendar and the list of events.

    How could I fix this problem?

    Thanx

    -jude

    #45121
    Franky
    Keymaster

    Change the line

    print "<h2><a href='".get_bloginfo('url')."/events/?event_id=".$row['event_id']."'>".$row['event_name']."</a> ".$row['event_start_date']."</h2>";

    to

    print eme_event_url($row);

    #45122
    Anonymous
    Inactive

    Thanks,

    the line is now

    print "<h2><a href='".eme_event_url($row)."'>".$row['event_name']."</a> ".$row['event_start_date']."</h2>";

    and it works fine. But there is still one issue: in the bottom of search results it reads “No posts found. Try a different search?”, even it found everything that can be found. This could be more WP issue, but is there any work around with this?

    -jude

    #45123
    Franky
    Keymaster

    Like others: see my example and place the “if (!$found_event)” statement correctly.

    #45124
    Anonymous
    Inactive

    Thanks Franky!

    You’re teacher, aren’t you? It works and maybe I learned something. Thanks a lot!

    -jude

    #45125
    Franky
    Keymaster

    A teacher? Not really, but I see your point 🙂

    #45126
    Anonymous
    Inactive

    hmm – i’m not getting any errors but my search still doesn’t show events – here is my search.php code:

    <?php
    /**
    * The template for displaying Search Results pages.
    *
    * @package WordPress
    * @subpackage Twenty_Eleven
    * @since Twenty Eleven 1.0
    */

    get_header(); ?>

    <?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 "<h2><a>".$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;
    }

    ?>

    <section id="primary">
    <div id="content" role="main">

    <?php if ( have_posts() ) : ?>

    <header class="page-header">
    <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentyeleven' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
    </header>

    <?php twentyeleven_content_nav( 'nav-above' ); ?>

    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>

    <?php
    /* Include the Post-Format-specific template for the content.
    * If you want to overload this in a child theme then include a file
    * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    */
    get_template_part( 'content', get_post_format() );
    ?>

    <?php endwhile; ?>

    <?php twentyeleven_content_nav( 'nav-below' ); ?>

    <?php else : ?>

    <article id="post-0" class="post no-results not-found">
    <header class="entry-header">
    <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
    </header><!-- .entry-header -->

    <div class="entry-content">
    <p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'twentyeleven' ); ?></p>
    <?php get_search_form(); ?>
    </div><!-- .entry-content -->
    </article><!-- #post-0 -->

    <?php endif; ?>

    </div><!-- #content -->
    </section><!-- #primary -->

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    #45127
    Franky
    Keymaster

    This works just fine:

    <?php
    /**
    * The template for displaying Search Results pages.
    *
    * @package WordPress
    * @subpackage Twenty_Eleven
    * @since Twenty Eleven 1.0
    */

    get_header(); ?>

    <?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 "<h2><a href='".eme_event_url($row)."'>".$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;
    }

    ?>

    <section id="primary">
    <div id="content" role="main">

    <?php if ( have_posts() ) : ?>

    <header class="page-header">
    <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentyeleven' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
    </header>

    <?php twentyeleven_content_nav( 'nav-above' ); ?>

    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>

    <?php
    /* Include the Post-Format-specific template for the content.
    * If you want to overload this in a child theme then include a file
    * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    */
    get_template_part( 'content', get_post_format() );
    ?>

    <?php endwhile; ?>

    <?php twentyeleven_content_nav( 'nav-below' ); ?>

    <?php else : ?>

    <?php if (!$found_event) : ?>

    <article id="post-0" class="post no-results not-found">
    <header class="entry-header">
    <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
    </header><!-- .entry-header -->

    <div class="entry-content">
    <p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'twentyeleven' ); ?></p>
    <?php get_search_form(); ?>
    </div><!-- .entry-content -->
    </article><!-- #post-0 -->

    <?php endif; ?>
    <?php endif; ?>

    </div><!-- #content -->
    </section><!-- #primary -->

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    #45128
    Anonymous
    Inactive

    thanks for the reply – i’ve inserted your code into search.php and the search still doesn’t find anything event related:

    http://cjehost.com/ns-sctf/course-information/event/test-event/

    search for anything besides the event name i.e.:

    “20 hrs 1A CME anticipated”

    “COURSE IS LIMITED TO 40 PARTICIPANTS”

    and no search results are found. I’ve copied and pasted your exact code into

    themes/twentyeleven/search.php

    #45129
    Franky
    Keymaster

    The search query I put here only looks in the event name and the event notes (the html field).

    #45130
    Anonymous
    Inactive

    Hello Franky,

    how can i insert a category name into code for search results? thanx a lot.

    #45131
    Anonymous
    Inactive

    Have been unable to get this working on my site. Can you please give a working example. I have followed the instructions above with no success 🙁

    This is my search.php code

    <?php get_header(); ?>

    <img src="/wp-content/themes/brightonss/images/internal_header.jpg" alt="" />

    <div id="content">

    <?php if ( have_posts() ) : ?>

    <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'Brighton Secondary School' ), '<span>' . get_search_query() . '</span>' ); ?></h1>

    <?php

    /* Run the loop for the search to output the results.

    * If you want to overload this in a child theme then include a file

    * called loop-search.php and that will be used instead.

    */

    get_template_part( 'loop', 'search' );

    ?>

    <?php else : ?>

    <div id="post-0" class="post no-results not-found">

    <h2 class="entry-title"><?php _e( 'Nothing Found', 'Brighton Secondary School' ); ?></h2>

    <div class="entry-content">

    <p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'Brighton Secondary School' ); ?></p>

    <?php get_search_form(); ?>

    </div><!-- .entry-content -->

    </div><!-- #post-0 -->

    <?php endif; ?>

    </div><!--#content -->

    </div><!--#contentwrap -->

    <?php get_footer(); ?>

    what must be changed?

    #45132
    Franky
    Keymaster

    you did not include any of the code I specified. Please do that.

    #45133
    Anonymous
    Inactive

    Argh. I’m a different poster from the above, but I can’t get this to work either. Here’s mine. I’ve tried swapping $s for the_search_query but I can’t get anything to appear.

    <?php

    global $options;

    foreach ($options as $value) {

    if (get_settings( $value ) === FALSE) { $$value = $value; } else { $$value = get_settings( $value ); }

    }

    $dateformat = get_option(‘date_format’);

    $timeformat = get_option(‘time_format’);

    get_header();

    if(get_query_var(‘author_name’)) :

    $curauth = get_userdatabylogin(get_query_var(‘author_name’));

    else :

    $curauth = get_userdata(get_query_var(‘author’));

    endif;

    ?>

    <div id=”content”>

    <div class=”wrap”>

    <div class=”sep sepinside”> </div>

    <div class=”column column-narrow”> </div><!– end .column-narrow –>

    <div class=”column column-double column-content column-last”>

    <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>

    <h1>Search Results for: <?php the_search_query(); ?></h1>

    </div><!– end .column-double –>

    <div class=”clear”> </div>

    <div class=”column column-narrow”>

    <?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘Sidebar: Archive Pages’) ) : ?> <?php endif; ?>

    </div><!– end .column-narrow –>

    <div class=”column column-double column-last”>

    <div class=”posts”>

    <?php

    /* Patched 3/2012 from Events Made Easy docs at http://www.e-dynamics.be/bbpress/topic.php?id=197 to include EME events in search */

    $table = $wpdb->prefix.”dbem_events”;

    $s = mysql_real_escape_string($_REQUEST); // 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>“.$row.” “.$row.”</h2>”;

    print substr($row,0,250).”[…]”;

    print “<div style=’clear:both;’></div>”;

    $found_event = true;

    }

    /* END OF EME PATCH */

    ?>

    <?php

    wp_reset_query();

    $i = 0;

    if (have_posts()) : while (have_posts()) : the_post();

    $i++;

    update_post_caches($posts);

    ?>

    <div class=”post”>

    <?php

    unset($img);

    if ( current_theme_supports( ‘post-thumbnails’ ) && has_post_thumbnail() ) {

    $attachedFile = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ” );

    $img = $attachedFile[0];

    }

    else{

    if ($proud_cf_use == ‘Yes’)

    {

    $img = get_post_meta($post->ID, $proud_cf_photo, true);

    } // if CF used

    else

    {

    if (!$img)

    {

    $img = catch_that_image($post->ID);

    }

    } // if CF not used

    }

    if ($img)

    {

    ?>

    <div class=”thumb”>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><img src=”<?php bloginfo(‘template_directory’); ?>/scripts/timthumb.php?h=80&w=120&zc=1&src=<?php echo $img ?>” alt=”<?php the_title(); ?>” class=”bordered” /></div>

    <?php

    }

    ?>

    <h2>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></h2>

    <p class=”postmetadata”><?php the_time(“$dateformat $timeformat”); ?> / #commentspost” title=”Jump to the comments” rel=”nofollow”><?php comments_number(‘no comments’,’1 comment’,’% comments’); ?><?php edit_post_link( __(‘EDIT’), ‘ / ‘, ”); ?></p>

    <div class=”info”><?php the_excerpt(); ?></div>

    <div class=”clear”> </div>

    </div><!– end .post –>

    <?php endwhile;

    else:

    ?>

    <h2>Sorry, there are no posts in this category.</h2>

    <?php

    endif; ?>

    <div class=”navigation”>

    <p><span class=”older”><?php next_posts_link(‘< older entries’) ?></span> <span class=”latest”><?php previous_posts_link(‘newer entries >’) ?></span></p>

    </div>

    </div><!– end .posts –>

    </div><!– end .column-content –>

    <div class=”clear”> </div>

    </div><!– end .wrap –>

    </div><!– end #content –>

    <?php get_footer(); ?>

    #45134
    Franky
    Keymaster

    Since my original howto 8 months ago (which was for Events Manager Extended), the name of the tables have changed. In this case, dbem_events has changed to eme_events. Just changing that should do it.

    #45135
    Anonymous
    Inactive

    Bingo. Thanks, Franky!

    Smaller bug — there’s a JPG image in the body of my test event, and the search result summary tries to show it, but returns a broken image icon instead.

    The event is a six word sentence, with an image below it. It’s a regular image in one of my WordPress upload directories, but the broken image URL is this:

    http://mysite.example.org/wp-content/uploads/2012/03/Beginning-of-Image-Name[...]%3Cdiv%20style='clear:both;'%3E%3C/div%3E%20%20%20%20%20%20%20%20%20%20%3Ch2%3ESorry,%20there%20are%20no%20posts%20in%20this%20category.%3C/h2%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class=

    As a workaround I was able to change the length of your line to “print substr($row,0,100” but of course that won’t work if the image appears before any text does.

    I would probably rather have it suppress the image anyway, but a broken image icon is bad form… Any advice?

    More importantly, it seems that unless I specify a /a tag AFTER your routine, currently at the beginning of my “Searching Posts” div, then there’s a hanging href reference going on (which explains the above — it’s pulling more from the next result). I’ve also added separators to distinguish between the Events search and the Pages/Posts search, as follows:

    <?php
    /* Patched 3/2012 from Events Made Easy docs at http://www.e-dynamics.be/bbpress/topic.php?id=197 to include EME events in search */

    print "<div class='sep'> </div><h1>Searching Events...</h1><br>";

    $table = $wpdb->prefix."eme_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>".$row['event_name']." ".$row['event_start_date']."</h2>";
    print substr($row['event_notes'],0,100)."...<br><br>";
    print "<div style='clear:both;'></div>";
    $found_event = true;
    }
    ?>

    <div class="post">
    <?php
    print "</a><div class='sep'> </div><h1>Searching Posts and Pages...</h1>";
    /* END OF EME PATCH */
    ?>
    </div>

    Obviously I’d like to get rid of the /a kludge — but I don’t really know PHP! Is this a bug in your routine?

    #45136
    Franky
    Keymaster

    the /a should not be needed. But to be sure, use this:

    print substr(eme_strip_tags($row['event_notes']),0,100)."...<br><br>";

    the function eme_strip_tags strips away all html tags, so no image problems any more.

    #45137
    Anonymous
    Inactive

    Cool, that works. Thank you Franky! (It turns out that the misbehavior was keeping additional event results from appearing too.)

    I also cleaned up my code a little and made the Event returns format more like my Posts and Pages returns. If anyone needs it, here’s my current working code:

    <?php
    /* Patched 3/2012 from Events Made Easy docs at http://www.e-dynamics.be/bbpress/topic.php?id=197 to include EME events in search */
    print "<div class='post'><div class='sep'> </div><h1>Searching Events...</h1></div>";
    $table = $wpdb->prefix."eme_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 "<div class='post'><h2><a href='".eme_event_url($row)."'>".$row['event_name']."</a> ".$row['event_start_date']."</h2>";
    print substr(eme_strip_tags($row['event_notes']),0,250)."...</div>";
    print "<div style='clear:both;'></div>";
    $found_event = true;
    }
    print "<div class='post'><div class='sep'> </div><h1>Searching Posts and Pages...</h1></div>";
    /* END OF EME PATCH */
    ?>

    #45138
    Anonymous
    Inactive

    HELP! I keep reading and re-reading these instructions but I just cannot work out where to put each bit of code in search.php I have failed at every attempt to find an event.

    <h2><?php $search_count = 0; $search = new WP_Query("s=$s & showposts=-1"); if($search->have_posts()) : while($search->have_posts()) : $search->the_post(); $search_count++; endwhile; endif; echo $search_count;?> <?php _e('Search results for','intent'); ?> <span>"<?php echo get_search_query(); ?>"</span></h2>
    </div><!--/page-title-inner-->
    </div><!--/page-title-->

    <div id="page">
    <div id="page-inner" class="container fix">

    <div id="content-part">
    <?php if(!have_posts()): ?>
    <article class="entry">
    <div class="text">
    <h1><?php _e('No search results','intent'); ?></h1>
    <p><?php _e('The good news is you can try again.','intent'); ?></p>
    <form role="search" method="get" action="<?php echo home_url('/'); ?>">
    <div class="fix">
    <input type="text" value="" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="<?php _e('Search','intent'); ?>" />
    </div>
    </form>
    <div class="clear"></div>
    </div>
    </article>
    <?php endif; ?>
    <?php get_template_part('_loop'); ?>
    </div><!--/content-part-->

    This is what I have now

    <h2><?php
    $table = $wpdb->prefix."eme_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='".eme_event_url($row)."'>".$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;
    }

    ?></h2>
    </div><!--/page-title-inner-->
    </div><!--/page-title-->

    <div id="page">
    <div id="page-inner" class="container fix">

    <div id="content-part">
    <?php if(!have_posts()): ?>
    <article class="entry">
    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>

    <?php
    /* Include the Post-Format-specific template for the content.
    * If you want to overload this in a child theme then include a file
    * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    */
    get_template_part( 'content', get_post_format() );
    ?>

    <?php endwhile; ?>

    <?php intent_content_nav( 'nav-below' ); ?>

    <?php else : ?>

    <?php if (!$found_event) : ?>

    <article id="post-0" class="post no-results not-found">
    <header class="entry-header">
    <h1 class="entry-title"><?php _e( 'Nothing Found', 'intent' ); ?></h1>
    </header><!-- .entry-header -->

    <div class="entry-content">
    <p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'intent' ); ?></p>
    <?php get_search_form(); ?>
    </div><!-- .entry-content -->
    </article><!-- #post-0 -->

    <?php endif; ?>
    <?php endif; ?>
    <?php get_template_part('_loop'); ?>
    </div><!--/content-part-->

    Please can you tell me where I am going wrong.

    #45139
    Franky
    Keymaster

    I haven’t looked at all your code, but I saw this:

    WP_Query("s=$s & showposts=-1");

    Did you include the extra spaces as an example? Because there shouldn’t be any:

    WP_Query("s=$s&showposts=-1");

    And to be honest: I haven’t looked at WP_Query yet, did you try with the examples mentioned above?

    #45140
    Anonymous
    Inactive

    Hi,

    Thank you. I have for this to work at last, but the results show in all languages instead of the language the site is being used in – using qTranslate

    Any suggestions?

    #45141
    Franky
    Keymaster

    If using qtranslate, use the function call eme_translate around $row and $row:

    … eme_translate($row) …

    … translate($row) …

    #45142
    Anonymous
    Inactive

    Thank you 🙂

    #52822
    Anonymous
    Inactive

    Hello

    I’m having trouble with implementing any of the suggested code for including search events in search results.

    Any time I add any of the suggested code to the search.php file (I’m using the code posted by Franky above on July 25, 2011 at 13:50), I get the following errors displayed when I test in the search field on the website:

    Parse error: syntax error, unexpected T_STRING in /home/culturen/public_html/wp-content/themes/duena/search.php on line 1

    I wonder is it perhaps a clash with my theme’s PHP (I’m using Duena – https://wordpress.org/themes/duena), or is this code outdated (I noticed the last post on this topic was over two years ago)?

    Any thoughts would be appreciated

    Cheers
    Jamie

    #52825
    Franky
    Keymaster

    Post your code.

    #52826
    Anonymous
    Inactive

    Error returned is:
    Parse error: syntax error, unexpected T_VARIABLE in /home/culturen/public_html/wp-content/themes/duena/search.php on line 9

    My search.php file is the below code:

    
    <?php
    
    /**
    
     * The template for displaying Search Results pages.
    
     *
    
     * @package duena
    
     */
    
    get_header(); ?>
    
    <?php
    
    $table = $wpdb->prefix."eme_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='".eme_event_url($row)."'>".$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;
    
    }
    
    ?>
    
    	<div id="primary" class="col-md-8 <?php echo esc_attr( of_get_option('blog_sidebar_pos') ) ?>">
    
    		<div id="content" class="site-content" role="main">
    
    		<?php if ( have_posts() ) : ?>
    
    			<header class="page-header">
    
    				<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'duena' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
    
    			</header><!-- .page-header -->
    
    			<?php /* Start the Loop */ ?>
    
    			<?php while (have_posts()) : the_post(); 			
    
    				// The following determines what the post format is and shows the correct file accordingly
    
    				$format = get_post_format();
    
    				get_template_part( 'post-formats/'.$format );					
    
    				if($format == '')
    
    				get_template_part( 'post-formats/standard' );					
    
    			endwhile; ?>
    
    		<?php else : ?>
    
    			<?php get_template_part( 'no', 'results' ); ?>
    
    		<?php endif; ?>
    
    		<?php get_template_part('post-formats/post-nav'); ?>
    
    		</div><!-- #content -->
    
    	</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>
    
    #52827
    Franky
    Keymaster

    You post a different error in the last post than the one mentioned before. Also: you’re only using part of the code (you never use the var called $found_event in the rest of search.php)
    Anyway, I don’t see anything wrong with that code, I even tried it locally and it seems to be working just fine.
    I even tried it with your theme and it seems to work just fine.
    Make sure you edited search.php the right way (no mixed windows and linux line endings …), and figure out what is at line 9 that might be the prob for you.

    #52830
    Anonymous
    Inactive

    Hi Franky

    Yes, I had edited it a bit between posts – hence the different error messages.

    Regardless, it now works. You were correct (as always), I had my editor set in a way that was messing up the windows and linux line endings.

    Thanks again for all your help

    Jamie

    #52831
    Franky
    Keymaster

    Glad to hear it works now.

    #53211
    Anonymous
    Inactive

    I just wanted to ask how to filter events that it only shows future ones, but I figured it out in the meantime. After all, there is an SQL query m( 😀

    This does the triock for me, so I want to share that:
    $query = “SELECT * FROM $table WHERE (event_start_date >= CURDATE()) AND ((event_name LIKE ‘%”.$s.”%’) OR (event_notes LIKE ‘%”.$s.”%’)) ORDER BY event_start_date”;

    After integrating this in the used theme it becomes clear, why there isn’t a generic approach in EME to include events in search results. If that were possible, it would be marvellous! But I don’t see that comin – too many different approches in different themes. Thanks for all the code examples from you and aothers and your comments!

    Best regards
    Floutsch

    #54269
    Franky
    Keymaster

    FYI, the following “old” code

    
    $table = $wpdb->prefix."eme_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 );
    

    should be replaced by the “better” code:

    
    $table = $wpdb->prefix."eme_events";
    $found_event = false;
    $query = "SELECT * FROM $table WHERE (event_name LIKE '%%".$s."%%') OR
    (event_notes LIKE '%%".$s."%%') ORDER BY event_start_date";
    $sql=$wpdb->prepare($query,$_REQUEST['s'],$_REQUEST['s']);
    $events = $wpdb->get_results ( $sql, ARRAY_A );
    
Viewing 33 posts - 1 through 33 (of 33 total)
  • The forum ‘How do I …’ is closed to new topics and replies.
Scroll to Top