Events Made Easy › Forums › How do I … › WordPress search for events
- This topic has 10 replies, 2 voices, and was last updated 2 years, 6 months ago by Franky.
-
AuthorPosts
-
Mon 25 Apr 2022 at 10:23 #64096AnonymousInactive
Hi Franky,
I’m following the FAQ but am struggling to implement the search facility as detailed in the FAQ.
I’m on a test site so am editing the main theme search.php – I’ve added the lines as shown in the FAQ but it’s not bringing any event detail back.
URL: https://test.learning.necsu.nhs.uk/
Event URL: https://test.learning.necsu.nhs.uk/events/traditional-music-session/I’m searching for ‘traditional’ but it’s finding no results. Search is working as expected for posts and pages.
search.php looks like:
‘$events = eme_wordpress_search_events();
<?php
/**
* The template for displaying search results pages
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
*
* @package WordPress
* @subpackage Twenty_Twenty_One
* @since Twenty Twenty-One 1.0
*/get_header();
if ( have_posts() || !empty($events) ) {
?>
<header class=”page-header alignwide”>
<h1 class=”page-title”>
<?php
printf(
/* translators: %s: Search term. */
esc_html__( ‘Results for “%s”‘, ‘twentytwentyone’ ),
‘<span class=”page-description search-term”>’ . esc_html( get_search_query() ) . ‘</span>’
);
?>
</h1>
</header><!– .page-header –><div class=”search-result-count default-max-width”>
<?php
printf(
esc_html(
/* translators: %d: The number of search results. */
_n(
‘We found %d result for your search.’,
‘We found %d results for your search.’,
(int) $wp_query->found_posts,
‘twentytwentyone’
)
),
(int) $wp_query->found_posts
);
?><?php foreach ($events as $event) {
print “<h2>“.$event[‘event_name’].” “.eme_localized_date($event[‘event_start’]).”</h2>”;
print substr($event[‘event_notes’],0,250).”[…]”;
print “<div style=’clear:both;’></div>”;
} ?></div><!– .search-result-count –>
<?php
// Start the Loop.
while ( have_posts() ) {
the_post();/*
* Include the Post-Format-specific template for the content.
* If you want to override 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( ‘template-parts/content/content-excerpt’, get_post_format() );
} // End the loop.// Previous/next page navigation.
twenty_twenty_one_the_posts_navigation();// If no content, include the “No posts found” template.
} else {
get_template_part( ‘template-parts/content/content-none’ );
}get_footer();
‘Hope you can help.
Mon 25 Apr 2022 at 10:39 #64109FrankyKeymasterYou have set your first line outside your php-tag, that will of course not work …
Mon 25 Apr 2022 at 12:43 #64111AnonymousInactiveThanks Franky.
I had it inside the php-tag and that didn’t work either, now looks like this and still doesn’t work – can’t see what I’m missing/done wrong.
<?php
/**
* The template for displaying search results pages
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
*
* @package WordPress
* @subpackage Twenty_Twenty_One
* @since Twenty Twenty-One 1.0
*/$events = eme_wordpress_search_events();
get_header();if ( have_posts() || !empty($events) ) {
?>
<header class=”page-header alignwide”>
<h1 class=”page-title”>
<?php
printf(
/* translators: %s: Search term. */
esc_html__( ‘Results for “%s”‘, ‘twentytwentyone’ ),
‘<span class=”page-description search-term”>’ . esc_html( get_search_query() ) . ‘</span>’
);
?>
</h1>
</header><!– .page-header –><div class=”search-result-count default-max-width”>
<?php
printf(
esc_html(
/* translators: %d: The number of search results. */
_n(
‘We found %d result for your search.’,
‘We found %d results for your search.’,
(int) $wp_query->found_posts,
‘twentytwentyone’
)
),
(int) $wp_query->found_posts
);
?><?php foreach ($events as $event) {
print “<h2>“.$event[‘event_name’].” “.eme_localized_date($event[‘event_start’]).”</h2>”;
print substr($event[‘event_notes’],0,250).”[…]”;
print “<div style=’clear:both;’></div>”;
} ?></div><!– .search-result-count –>
<?php
// Start the Loop.
while ( have_posts() ) {
the_post();/*
* Include the Post-Format-specific template for the content.
* If you want to override 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( ‘template-parts/content/content-excerpt’, get_post_format() );
} // End the loop.// Previous/next page navigation.
twenty_twenty_one_the_posts_navigation();// If no content, include the “No posts found” template.
} else {
get_template_part( ‘template-parts/content/content-none’ );
}get_footer();
Mon 25 Apr 2022 at 13:59 #64112FrankyKeymasterThat should work just fine … I tried it here on my theme and got the expected results. Can you demo this on a site for me? Could I have some admin to test?
Mon 25 Apr 2022 at 14:08 #64113AnonymousInactiveHi Franky,
Just checked again and it turns out it’s a plugin conflict with the BuddyBoss platform which we use – thought I’d best let you know in case it comes up again. The search code you supplied works fine when that plugin isn’t activated.
I’ve logged a support call with BuddyBoss to investigate.
Thanks,
David.Mon 25 Apr 2022 at 15:20 #64114FrankyKeymasterI don’t know that plugin, but if anything can be implemented on my end to resolve this conflict I’m willing to take a look at it (BuddyBoss will need to give feedback though).
Tue 26 Apr 2022 at 16:22 #64118AnonymousInactiveCheers Franky – just waiting to hear back from them. I’ll let you know.
Fri 29 Apr 2022 at 13:59 #64152AnonymousInactiveHi Franky,
Just heard back from BuddyBoss, their reply is:
This is to inform you that, when the BuddyBoss Platform is active, it actually replaces WordPress’s default searching with the BuddyBoss network search functionality and the custom code (which you provide in the FAQs) is not compatible with the BuddyBoss Network search.
I don’t know if this is something you’d look at? I could provide you access to a staging site if required.
Thanks,
DavidFri 29 Apr 2022 at 14:06 #64153FrankyKeymasterSorry, but no. EME doesn’t use custom post types, so the only solution is for buddyboss to allow to hook into their system then. But it seems buddyboss also interferes with your theme then, which is very weird.
Fri 29 Apr 2022 at 14:41 #64154AnonymousInactiveThanks Franky, BuddyBoss is a theme and platform plugin all in one. It’s an extension of BuddyPress.
Is there a way to tag events in EME and for the tags to be searchable without the custom code you have shared in the FAQ?
Fri 29 Apr 2022 at 15:39 #64157FrankyKeymasterIf budyboss uses only custom post types that won’t help you. EME events have categories (managed all in EME), but not wordpress tags (switching EME to custom post types would lead to about a year of work …).
-
AuthorPosts
- The forum ‘How do I …’ is closed to new topics and replies.