bluvertigo
6/24/2015 - 7:20 AM

Ricerca Personalizzata / Custom Search - Shortcode ricerca

Ricerca Personalizzata / Custom Search - Shortcode ricerca

<?php
/**
 * Template Name: Search Page
 *
 *
 * @package WooFramework
 * @subpackage Template
 */

 get_header();
 global $woo_options;
?>      
    <!-- #content Starts -->
    <?php woo_content_before(); ?>
    <div id="content" class="col-full">
    
        <div id="main-sidebar-container">    
        
            <!-- #main Starts -->
            <?php woo_main_before(); ?>
            <section id="main" class="col-left">
                
            <?php get_template_part( 'loop', 'search_custom' ); ?>
                    
            </section><!-- /#main -->
            <?php woo_main_after(); ?>
    
            <?php get_sidebar(); ?>
    
        </div><!-- /#main-sidebar-container -->         

        <?php get_sidebar( 'alt' ); ?>       

    </div><!-- /#content -->
    <?php woo_content_after(); ?>
        
<?php get_footer(); ?>
<?php
/**
 * Loop - Search
 *
 * This is the loop logic used on the search results screen.
 *
 * @package WooFramework
 * @subpackage Template
 */
 global $more; $more = 0;
 
woo_loop_before();

$search = ($_GET['search'] != '' ? $_GET['search'] : '');

$da_mq = ($_GET['da_mq'] != '' ? $_GET['da_mq'] : 0);


$a_mq = ($_GET['a_mq'] != '' ? $_GET['a_mq'] : 9999999999);

$da_prezzo = ($_GET['da_prezzo'] != '' ? $_GET['da_prezzo'] : 0);
$da_prezzo = str_replace(",", "", str_replace(".", "", $da_prezzo));

$a_prezzo = ($_GET['a_prezzo'] != '' ? $_GET['a_prezzo'] : 9999999999);
$a_prezzo = str_replace(",", "", str_replace(".", "", $a_prezzo));

$tipologia = ($_GET['tipologia'] != '' ? $_GET['tipologia'] : '');

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$args = array(
	'post_type' => 'post',
	's' => $search,
	'paged' => $paged,
	'posts_per_page' => 5,
	'category_name' => $tipologia,
	'meta_key' => 'search_prezzo',
	'orderby' => 'meta_value_num',
	'order' => 'ASC',
	'meta_query' => array(
		array(
			'key' => 'search_mq',
			'value'   => array( $da_mq, $a_mq ),
			'type'    => 'numeric',
			'compare' => 'BETWEEN',
		),
		array(
			'key' => 'search_prezzo',
			'value'   => array( $da_prezzo, $a_prezzo ),
			'type'    => 'numeric',
			'compare' => 'BETWEEN',
		),
	),
);

// $args = array(
// 	'post_type' => 'post',
// 	's' => $s
// );


$query = new WP_Query( $args );

if ($query->have_posts()) { $count = 0;

	$title_before = '<h1 class="archive_header">';
	$title_after = '</h1>';
	
	echo $title_before . 'Risultati della ricerca' . $title_after;
?>
<!--<a href="<?php echo home_url( '/' ) . $_GET['search_form_page']; ?>">Torna al modulo di ricerca</a>-->
<div class="fix"></div>

<?php
	while ($query->have_posts()) { $query->the_post(); $count++;
	
		if (get_option('woo_woo_tumblog_switch') == 'true') { $is_tumblog = woo_tumblog_test(); } else { $is_tumblog = false; }

		woo_get_template_part( 'content', 'search-custom' );

	} // End WHILE Loop
} else {
	get_template_part( 'content', 'noposts' );
} // End IF Statement

woo_loop_after();

woo_pagenav($query);
?>
/* SHORTCODE */
function wpbsearchform( $atts, $form ) {

	$atts = shortcode_atts(
			array(
				'search_page' => 'cerca',
				'search_form_page' => 'modulo-ricerca',
				'tipo1' => 'vendita',
				'tipo2' => 'affitto'
			), $atts);

	$tipologia = $_GET['tipologia'];

	$select_tipo1 =  "";
	$select_tipo2 =  "";

	echo var_dump($tipologia);

	if( isset( $_GET['tipologia'] ) )
		if( $tipologia == $atts['tipo1'] ) {
			$select_tipo1 =  "selected";
		} else {
			$select_tipo2 =  "selected";
		}

	$a_prezzo = "";
	if( isset( $_GET['a_prezzo'] ) ) $a_prezzo = sanitize_text_field( $_GET['a_prezzo'] );

	$da_prezzo = "";
	if( isset( $_GET['da_prezzo'] ) ) $da_prezzo = sanitize_text_field( $_GET['da_prezzo'] );
	
	$a_mq = "";
	if( isset( $_GET['a_mq'] ) ) $a_mq = sanitize_text_field( $_GET['a_mq'] );

	$da_mq = "";
	if( isset( $_GET['da_mq'] ) ) $da_mq = sanitize_text_field( $_GET['da_mq'] );

	$search = "";
	if( isset( $_GET['search'] ) ) $search = sanitize_text_field( $_GET['search'] );

    $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . $atts['search_page'] . '/' . '" >
    <div><label class="screen-reader-text" for="search">' . 'Parola chiave:' . '</label>
    <input type="text" value="'.$search.'" name="search" id="search" /><br/>
    <div class=""><label class="screen-reader-text" for="da_prezzo">' . 'Prezzo minimo:' . '</label>
    <input type="text" value="'.$da_prezzo.'" name="da_prezzo" id="da_prezzo" /></div>
    <div class=""><label class="screen-reader-text" for="a_prezzo">' . 'Prezzo massimo:' . '</label>
    <input type="text" value="'.$a_prezzo.'" name="a_prezzo" id="a_prezzo" /></div>
    <div class=""><label class="screen-reader-text" for="da_mq">' . 'Da mq:' . '</label>
    <input type="text" value="'.$da_mq.'" name="da_mq" id="da_mq" /></div>
    <div class=""><label class="screen-reader-text" for="a_mq">' . 'A mq:' . '</label>
    <input type="text" value="'.$a_mq.'" name="a_mq" id="a_mq" /></div>
    <label class="screen-reader-text" for="tipologia">' . 'Tipologia:' . '</label>
    <select id="tipologia" name="tipologia" >
  		<option value="'. $atts['tipo1'] .'" '. $select_tipo1 .' >'. ucfirst($atts['tipo1'])  .'</option>
  		<option value="'. $atts['tipo2'] .'" '. $select_tipo2 .' >'. ucfirst($atts['tipo2'])  .'</option>
	</select><br/>
    <input type="hidden" value="' . $atts['search_form_page'] . '" name="search_form_page" id="search_form_page" />
    <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
    </div>
    </form>';
    return $form;
}
add_shortcode('custom_search_form', 'wpbsearchform');
<?php
/**
 * Post Content Template
 *
 * This template is the default page content template. It is used to display the content of the
 * `single.php` template file, contextually, as well as in archive lists or search results.
 *
 * @package WooFramework
 * @subpackage Template
 */

/**
 * Settings for this template file.
 *
 * This is where the specify the HTML tags for the title.
 * These options can be filtered via a child theme.
 *
 * @link http://codex.wordpress.org/Plugin_API#Filters
 */

$settings = array(
				'thumb_w' => 100,
				'thumb_h' => 100,
				'thumb_align' => 'alignleft',
				'post_content' => 'excerpt',
				'comments' => 'both'
				);

$settings = woo_get_dynamic_values( $settings );

$title_before = '<h1 class="title entry-title">';
$title_after = '</h1>';

if ( ! is_single() ) {
	$title_before = '<h2 class="title entry-title">';
	$title_after = '</h2>';
$title_before = $title_before . '<a href="' . esc_url( get_permalink( get_the_ID() ) ) . '" rel="bookmark" title="' . the_title_attribute( array( 'echo' => 0 ) ) . '">';
$title_after = '</a>' . $title_after;
}

$page_link_args = apply_filters( 'woothemes_pagelinks_args', array( 'before' => '<div class="page-link">' . __( 'Pages:', 'woothemes' ), 'after' => '</div>' ) );

woo_post_before();
?>
<article <?php post_class(); ?>>
<?php
	woo_post_inside_before();
	if ( 'content' != $settings['post_content'] && ! is_singular() )
		woo_image( 'width=' . esc_attr( $settings['thumb_w'] ) . '&height=' . esc_attr( $settings['thumb_h'] ) . '&class=thumbnail ' . esc_attr( $settings['thumb_align'] ) );
?>
	<header>
		<?php the_title( $title_before, $title_after ); ?>
		<section class="container_label">

			<?php
			$search_mq = get_post_meta( get_the_ID(), 'search_mq', true );
			$search_prezzo = get_post_meta( get_the_ID(), 'search_prezzo', true );
			?>

		    <ul class="tags">
		    	<?php
				if( ! empty( $search_mq ) ) {
				  echo '<li><a href="#">mq <span>'.$search_mq.'</span></a></li>';
				}  

				if( ! empty( $search_prezzo ) ) {
					$search_prezzo_formattato =  number_format($search_prezzo, 2, ',', '.');
				  	echo '<li><a href="#">prezzo <span>&euro;&nbsp;'. $search_prezzo_formattato .'</span></a></li>';
				} 
				?>
		      
		    </ul>
		</section>
	</header>

<?php
	woo_post_meta();
?>
	<section class="entry">
	    <?php
	    	 the_excerpt();
	    ?>
	</section><!-- /.entry -->
	<div class="fix"></div>
<?php
	woo_post_inside_after();
?>
</article><!-- /.post -->
<?php
woo_post_after();
$comm = $settings['comments'];
if ( ( 'post' == $comm || 'both' == $comm ) && is_single() ) { comments_template(); }
?>