Extrace Search Box
-
Greetings. Again with my site. now i need to place the search box on the header.
I managed to place it but i have this result:And once i so a search i don’t see anything. I placed on the header file the following string
<?php /** * Header * * @package theme */ ?> <header> <div class="top"> <?php get_template_part( 'view/component/logo' ); ?> <a href="javascript:;" class="search-control"><?php the_acf_option( 'label_search' ); ?></a> <a href="javascript:;" class="menu-control"><?php the_acf_option( 'label_menu' ); ?></a> <?php /*get_template_part( 'view/module/search' );*/ /*get_template_part( 'view/component/cta' );*/ dynamic_sidebar( 'SearchBox' ); //include ADVERTS_PATH . '/templates/list.php'; //global $wp_query; remove_filter("the_content", "adverts_the_content"); echo shortcode_adverts_list(array( "category" => $wp_query->get_queried_object_id() )); dynamic_sidebar( 'CTA' ); ?> </div> <div class="nav"> <?php wp_nav_menu( [ 'menu' => 'main', 'fallback_cb' => null, ] ); ?> </div> </header>
I’m not sure what’s needed to be done but what i need first is solve the functionality before customizing the appearance.
Tried as well to do a custom shortcode on functions but does not work on the header; works in pages but when i use it wirks nut does not show results. Here it is:
add_shortcode('adverts_search', 'shortcode_adverts_search'); function shortcode_adverts_search( $atts ) { wp_enqueue_style( 'adverts-frontend' ); wp_enqueue_style( 'adverts-icons' ); wp_enqueue_script( 'adverts-frontend' ); $params = shortcode_atts(array( 'name' => 'default', 'author' => null, 'redirect_to' => '', 'search_bar' => adverts_config( 'config.ads_list_default__search_bar' ), 'show_results' => false, 'category' => null, 'columns' => adverts_config( 'config.ads_list_default__columns' ), 'display' => adverts_config( 'config.ads_list_default__display' ), 'switch_views' => adverts_config( 'config.ads_list_default__switch_views' ), 'allow_sorting' => 0, 'order_by' => 'date-desc', 'paged' => adverts_request("pg", 1), 'posts_per_page' => adverts_config( 'config.ads_list_default__posts_per_page' ), 'show_pagination' => true ), $atts, 'adverts_list' ); extract( $params ); if( is_numeric( $redirect_to ) ) { $action = get_permalink( $redirect_to ); } else { $action = $redirect_to; } $taxonomy = null; $meta = array(); $orderby = array(); $query = adverts_request("query"); $location = adverts_request("location"); if($location) { $meta[] = array('key'=>'adverts_location', 'value'=>$location, 'compare'=>'LIKE'); } if( is_string( $category) && $category == "current" && is_tax( "advert_category") ) { $category = get_queried_object_id(); } if($category) { $taxonomy = array( array( 'taxonomy' => 'advert_category', 'field' => 'term_id', 'terms' => $category, ), ); } if($allow_sorting && adverts_request("adverts_sort")) { $adverts_sort = adverts_request("adverts_sort"); } else { $adverts_sort = $order_by; } // options: title, post_date, adverts_price $sort_options = apply_filters( "adverts_list_sort_options", array( "date" => array( "label" => __("Publish Date", "wpadverts"), "items" => array( "date-desc" => __("Newest First", "wpadverts"), "date-asc" => __("Oldest First", "wpadverts") ) ), "price" => array( "label" => __("Price", "wpadverts"), "items" => array( "price-asc" => __("Cheapest First", "wpadverts"), "price-desc" => __("Most Expensive First", "wpadverts") ) ), "title" => array( "label" => __("Title", "wpadverts"), "items" => array( "title-asc" => __("From A to Z", "wpadverts"), "title-desc" => __("From Z to A", "wpadverts") ) ) ) ); $sarr = explode("-", $adverts_sort); $sort_current_text = __("Publish Date", "wpadverts"); $sort_current_title = sprintf( __( "Sort By: %s - %s", "wpadverts"), __("Publish Date", "wpadverts"), __("Newest First", "wpadverts") ); if( isset( $sarr[1] ) && isset( $sort_options[$sarr[0]]["items"][$adverts_sort] ) ) { $sort_key = $sarr[0]; $sort_dir = $sarr[1]; if($sort_dir == "asc") { $sort_dir = "ASC"; } else { $sort_dir = "DESC"; } if($sort_key == "title") { $orderby["title"] = $sort_dir; } elseif($sort_key == "date") { $orderby["date"] = $sort_dir; } elseif($sort_key == "price") { $orderby["adverts_price__orderby"] = $sort_dir; $meta["adverts_price__orderby"] = array( 'key' => 'adverts_price', 'type' => 'NUMERIC', 'compare' => 'NUMERIC', ); } else { // apply sorting using adverts_list_query filter. } $sort_current_text = $sort_options[$sort_key]["label"] ; $s_descr = $sort_options[$sort_key]["items"][$adverts_sort]; $sort_current_title = sprintf( __( "Sort By: %s - %s", "wpadverts"), $sort_current_text, $s_descr ); } else { $adverts_sort = $order_by; $orderby["date"] = "desc"; } $args = apply_filters( "adverts_list_query", array( 'author' => $author, 'post_type' => 'advert', 'post_status' => 'publish', 'posts_per_page' => $posts_per_page, 'paged' => $paged, 's' => $query, 'meta_query' => $meta, 'tax_query' => $taxonomy, 'orderby' => $orderby ), $params); if( ( $category || isset( $params["tax__advert_category"] ) ) && is_tax( 'advert_category' ) ) { $pbase = get_term_link( get_queried_object()->term_id, 'advert_category' ); } else { $pbase = get_the_permalink(); } $loop = new WP_Query( $args ); $paginate_base = apply_filters( 'adverts_list_pagination_base', $pbase . '%_%' ); $paginate_format = stripos( $paginate_base, '?' ) ? '&pg=%#%' : '?pg=%#%'; include_once ADVERTS_PATH . 'includes/class-html.php'; include_once ADVERTS_PATH . 'includes/class-form.php'; if( $switch_views && in_array( adverts_request( "display", "" ), array( "grid", "list" ) ) ) { $display = adverts_request( "display" ); add_filter( "adverts_form_load", "adverts_form_search_display_hidden" ); } if( $display == "list" ) { $columns = 1; } if( adverts_request( "reveal_hidden" ) == "1" ) { add_filter( "adverts_form_load", "adverts_form_search_reveal_hidden" ); } $form_scheme = apply_filters( "adverts_form_scheme", Adverts::instance()->get("form_search"), $params ); $form = new Adverts_Form( $form_scheme ); $form->bind( stripslashes_deep( $_GET ) ); $fields_hidden = array(); $fields_visible = array(); $counter = array( "visible-half" => 0, "visible-full" => 0, "hidden-half" => 0, "hidden-full" => 0 ); foreach($form->get_fields() as $field) { $search_group = "hidden"; $search_type = "half"; if( isset( $field['meta']["search_group"] ) ) { $search_group = $field['meta']['search_group']; } if( isset( $field['meta']['search_type'] ) ) { $search_type = $field['meta']['search_type']; } $counter[ $search_group . '-' . $search_type ]++; if( $search_type == 'full' ) { $field['adverts_list_classes'] = 'advert-input-type-full'; } else if( $counter[ $search_group . '-' . $search_type ] % 2 == 0 ) { $field['adverts_list_classes'] = 'advert-input-type-half advert-input-type-half-right'; } else { $field['adverts_list_classes'] = 'advert-input-type-half advert-input-type-half-left'; } if( $search_group == "visible" ) { $fields_visible[] = $field; } else { $fields_hidden[] = $field; } } // adverts/templates/list.php ob_start(); include apply_filters( "adverts_template_load", get_template_directory() . '/search.php' ); return ob_get_clean(); }
Thanks in advance.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Extrace Search Box’ is closed to new replies.