Forum Replies Created
-
AuthorPosts
-
Thank God i found a solution!
For anyone with this problem:
Add this to your functions.php file.
function random_search_result( $q ) {
if ( is_search() && is_main_query() )
$q->set( ‘orderby’, ‘rand’);
}
add_action( ‘pre_get_posts’, ‘random_search_result’ );That’s it!
Thanks for the support Kriesi! Fantastic like always!
Pieter
Hmm it doesn’t work.
I have already managed to show my search results in a grid.
Now i just need to make it random. Why? Because it’s a restaurant listing website. I want to show them random so it’s not always the same restaurant first you see?
Thanks!
Pieter
Hey!
It works like a charm! Thanks a lot man!
Top support, love enfold!
Cheers!
Hey Elliott,
First of all, Thanks for your quick response! Appreciate it
Here is the code i’ve used in search.php
<?php
global $avia_config;/*
* get_header is a basic wordpress function, used to retrieve the header.php file in your theme directory.
*/
get_header();$results = avia_which_archive();
echo avia_title(array(‘title’ => $results ));
?><div class=’container_wrap container_wrap_first main_color <?php avia_layout_class( ‘main’ ); ?>’>
<div class=’container’>
<main class=’content template-search <?php avia_layout_class( ‘content’ ); ?> units’ <?php avia_markup_helper(array(‘context’ => ‘content’));?>>
<div class=’page-heading-container clearfix’>
<section class=”search_form_field”>
<?php
echo “<h4>”.__(‘Andere zoekopdracht’,’avia_framework’).”</h4>”;
echo “<p>”.__(‘Vul hier Uw nieuwe zoekopdracht in:’,’avia_framework’).”</p>”;get_search_form();
echo “<span class=’author-extra-border’></span>”;
?>
</section>
</div><?php
if(!empty($_GET[‘s’]))
{
echo “<h4 class=’extra-mini-title widgettitle’>{$results}</h4>”;global $posts;
$post_ids = array();
foreach($posts as $post) $post_ids[] = $post->ID;$atts = array(
‘type’ => ‘grid’,
‘items’ => get_option(‘posts_per_page’),
‘columns’ => 4,
‘class’ => ‘avia-builder-el-no-sibling’,
‘paginate’ => ‘yes’,
‘use_main_query_pagination’ => ‘yes’,
‘custom_query’ => array( ‘post__in’=>$post_ids, ‘post_type’=>get_post_types() )
);$blog = new avia_post_slider($atts);
$blog->query_entries();
echo “<div class=’entry-content’>”.$blog->html().”</div>”;
}?>
<!–end content–>
</main><?php
//get the sidebar
$avia_config[‘currently_viewing’] = ‘page’;get_sidebar();
?>
</div><!–end container–>
</div><!– close default .container_wrap element –>
<?php get_footer(); ?>
-
AuthorPosts