0

i trying to make the search on drupal show result by date. for example if i type 25/05/2010 it should return posts for that date and also search by key work which is default on the search. how can i acheive that.

function mytheme_preprocess_search_result(&$variables) {
    $result_node = $variables['result']['node'];
    $image_realpath="";
    if(!empty($result_node->field_op_main_image)){
        $image_field = $result_node->field_op_main_image;
        $image_realpath = file_create_url($image_field['und']['0']['uri']);
    }
    $variables['image_uri'] = $image_realpath;
    $author_name="";
    $info = "";
    if(!empty($result_node->field_op_author)){
        $author = $result_node->field_op_author;
        $lang = $result_node->language;
        $author_id = $author[$lang]['0']['nid'];
        $author_detail = node_load($author_id);
        $author_name = $author_detail->title;
        $info .= $author_name . ' - ';
    }
    if(!empty($result_node->field_date)){
        $date_obj = $result_node->field_date;
        $date_val = $date_obj['und']['0']['value'];
        $info .= date('d/m/Y', strtotime($date_val));
    }
    $variables['info'] = $info;
    // dpm($variables);

above is the code for displaying my result for now.

please help thanks

=======================================================================

EDITED

so this is what i got so far: let me try to explain:

i was trying to modify the search-form and the search-block-form i was able to add a jquery date picker so that the user might search for a specific date or a key word.

the date picker is working

now the issue is:

when i search for key words and press submit it return the article with key word. but if i enter date only it give error to enter keyword and if i enter keyword and date it search by keyword only and ignore the date

code is below

// function to modify search form function fiveplus_form_alter(&$form, &$form_state, $form_id) {

// $variables['form']['actions']['submit']['#value'] = 'search';
if((array_key_exists('#id', $form) && $form['#id'] == 'search-block-form')){
    $form['actions']['submit']['#value'] = '';
}
if((array_key_exists('#id', $form) && $form['#id'] == 'search-form')){


    $form['basic']['submit']['#value'] = 'submit';
    $form['basic']['keys']['date_field']['#title'] = 'search';
    $form['basic']['date_field'] = array('#type' => 'date_popup','#date_format' => 'Y-m-d');
    dpm($form_state);
    //$form['advanced'] ;
}

so anyone can help me figure out how to make a user be able to search only by 1. date 2. date and keyword 3. keyword

thank you

  • Is there any reason you are not using views module? – Collins Jan 21 '15 at 9:01
  • am not sure how to do it in view?? Will it give user the option to pick a date and search ?? – teerdev ragudu Jan 21 '15 at 12:39
0

You can use views to search all of your content.

Rather than me write out every step for you, Please try the tutorial at http://webwash.net/tutorials/how-create-search-pages-using-views-drupal-7

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.