Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Center area post/pages (http://forum.bytesforall.com/forumdisplay.php?f=32)
-   -   [SOLVED] How to sort custom search results? (http://forum.bytesforall.com/showthread.php?t=11849)

blogmom Dec 22, 2010 12:45 AM

[SOLVED] How to sort custom search results?
 
I copied index.php to search.php as described here http://forum.bytesforall.com/showthread.php?t=610 and it works fine. But I am left confused with two questions:

1. how to sort the search results (by a custom field)?
2. how to specify/override the number of search results returned?

the contents of my search.php is basically:
PHP Code:

<?php     /* get all options: */
# error_reporting(-1);
include (TEMPLATEPATH '/functions/bfa_get_options.php');
global 
$bfa_ata;
get_header(); ?>

<?php /* If there are any posts: */
if (have_posts()) : $bfa_ata['postcount'] = 0/* Postcount needed for option "XX first posts full posts, rest excerpts" */ ?>

//MY CODE IS HERE
            
    <?php /* END of the LOOP */
    
endwhile; ?>


<?php /* END of: If there are any posts */
else : /* If there are no posts: */ ?>

<?php /* This outputs the "Not Found" content, if neither posts, pages nor attachments are available for the requested page.
This can be edited at Atahualpa Theme Options -> Style & edit the Center column */
bfa_center_content($bfa_ata['content_not_found']); ?>

<?php endif; /* END of: If there are no posts */ ?>


<?php get_footer(); ?>

Any help with this would be great. Running Atahualpa v.3.5.3 thanks....

juggledad Dec 22, 2010 06:06 AM

Without seeing the code you used, it's hard to tell.

You should look up what ever function you are using and read about the options (http://codex.wordpress.org/Function_Reference/) to see if there is an 'order by' option

blogmom Dec 22, 2010 02:49 PM

That's what confuses me too, I don't know the function being executed for a search. I activated the Search box in Atahualpa theme options and that's what I use to search. the only customization I have done is copy index.php and rename it to search.php, but I'm using the default search box from atahualpa theme options.

blogmom Dec 25, 2010 11:44 PM

After typing something in the search box, the URL becomes: www.mysite.com/?s=test Does that look familiar to anyone? Like JD says, if I could figure out which function is being called I might be able to customize it.

juggledad Dec 26, 2010 05:09 AM

see http://codex.wordpress.org/Creating_a_Search_Page

blogmom Dec 28, 2010 03:58 PM

hmmm... well. i guess that counts as an answer, albeit a cryptic one. took a while to piece this together but finally here is the solution in case anyone else gets stuck on this.

copy index.php to a new file named search.php in the atahualpa theme directory.
edit it as below:

PHP Code:

<?php
/* get all options: */
# error_reporting(-1);
include (TEMPLATEPATH '/functions/bfa_get_options.php');
global 
$bfa_ata;
get_header();

global 
$query_string;
global 
$paged;

$query_args explode("&"$query_string);
$search_query = array(
                      
'posts_per_page' => '50',
                      
'meta_key' => 'something',
                      
'orderby' => 'meta_value',
                      
'order' => 'ASC'
                     
);

foreach(
$query_args as $key => $string
{
    
$query_split explode("="$string);
    
$search_query[$query_split[0]] = $query_split[1];

 

$search = new WP_Query($search_query);
if (
$search->have_posts()) {
   
$searchcount=0;
   
$total_results $search->found_posts;
   
$tmp "<div class=\"something\">Search Results (total: " $total_results;
   if (
$total_results>50
   {
     
$tmp $tmp ", showing 50 per page)>";
   } else {
     
$tmp $tmp ")"
   }
   echo 
$tmp;

   

start a <TABLEtag or DIVs here to put the results into

<?php  
while ($search->have_posts()) : $search->the_post();
       
fill up your <TABLEhere
endwhile;

end your <TABLE> or DIV


} else { /* If there are no posts: */

bfa_center_content($bfa_ata['content_not_found']);

}

bfa_center_content($bfa_ata['center_content_bottom']);
get_footer(); 

?>

took a while to figure out how to do pagination in the results too but what the heck here is the secret: http://www.kriesi.at/archives/how-to...without-plugin hope this helps someone. Setting as SOLVED


All times are GMT -6. The time now is 03:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.