Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme » Center area post/pages »

[SOLVED] How to sort custom search results?


  #1  
Old Dec 22, 2010, 12:45 AM
blogmom
 
24 posts · Jun 2009
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....
  #2  
Old Dec 22, 2010, 06:06 AM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
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
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #3  
Old Dec 22, 2010, 02:49 PM
blogmom
 
24 posts · Jun 2009
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.
  #4  
Old Dec 25, 2010, 11:44 PM
blogmom
 
24 posts · Jun 2009
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.
  #5  
Old Dec 26, 2010, 05:09 AM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
see http://codex.wordpress.org/Creating_a_Search_Page
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #6  
Old Dec 28, 2010, 03:58 PM
blogmom
 
24 posts · Jun 2009
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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search Results kpkes@yahoo.com Center area post/pages 4 Jul 16, 2012 02:57 AM
search bar results three50seven Header configuration & styling 1 Sep 4, 2010 06:22 AM
Template for search results kjetil Center area post/pages 1 Jun 14, 2010 04:06 AM
wp-custom-fields-search Results Not displaying Byline/Footer joan Plugins & Atahualpa 1 Sep 17, 2009 10:38 AM


All times are GMT -6. The time now is 08:18 AM.


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