Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Есть произвольный тип записи в function.php выглядит так:
- /* Регистрируем Лучшее и таксономию для них
- -----------------------------------------------*/
- add_action('init', 'thebest');
- function thebest()
- {
- $labels = array(
- 'name' => 'Лучшее',
- 'singular_name' => 'Лучшее',
- 'add_new' => 'Добавить лучшее',
- 'add_new_item' => 'Добавить новую позиию',
- 'edit_item' => 'Редактировать лучшее',
- 'new_item' => 'Новая позиция',
- 'view_item' => 'Посмотреть лучшее',
- 'search_items' => 'Найти лучшее',
- 'not_found' => 'Лучшее не найдено',
- 'not_found_in_trash' => 'В корзине лучшее не найдено',
- 'parent_item_colon' => '',
- 'menu_name' => 'Лучшее'
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'query_var' => true,
- 'rewrite' => true,
- 'capability_type' => 'post',
- 'has_archive' => true,
- 'hierarchical' => false,
- 'menu_position' => 5,
- 'menu_icon' => 'dashicons-heart',
- 'supports' => array('title','editor','thumbnail','comments','custom-fields', 'author'),
- 'taxonomies' => array('thebests')
- );
- register_post_type('thebest',$args);
- }
- register_taxonomy( 'rubrika-thebest', 'thebest', array( 'hierarchical' => true, 'label' => 'Рубрики', 'query_var' => true, 'rewrite' => true ) );
- На странице page-best.php создаю форму:
- <form action="" method="get">
- <p><label>Поисковый запрос</label><br />
- <input type="text" name="word" value=""></p>
- <p><label>Диапазон цены</label><br />
- от <input type="text" name="min-price" size="3" value="">
- до <input type="text" name="max-price" size="3" value=""></p>
- <input type="submit" name="meta_key" value="price-products">
- </form>
- На этой же странице вывожу в цикле
- <?php
- $args = array(
- 'post_type' => 'thebest',
- 's' => $_GET['word'],
- 'meta_key' => $_GET['meta_key'],
- 'posts_per_page' => $_GET['num'],
- 'paged' => get_query_var( 'paged' ),
- 'order' => $_GET['order'],
- 'orderby' => $_GET['orderby'],
- 'tax_query' => array(
- array(
- 'taxonomy' => 'rubrika-thebest',
- 'field' => 'id',
- 'terms' => array($_GET['rubrika-thebest'])
- )
- ),
- 'meta_query' => array(
- array(
- 'key' => 'product-price',
- 'value' => array( (int)$_GET['min-price'], (int)$_GET['max-price'] ),
- 'type' => 'numeric',
- 'compare' => 'BETWEEN'
- )
- )
- );
- query_posts( $args ); ?>
- Сам цикл
- <?php $thebest = new WP_Query( array( 'post_type' => 'thebest', 'posts_per_page' => 30 ) ); ?>
- <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
- <?php endwhile; else: ?><p>Извините, но у нас пока нет информации о товарах и услугах с выгодными ценами.</p>
- <?php endif; ?>
- <div id="looop" class="liist">
- <?php while ( $thebest->have_posts() ) : $thebest->the_post(); ?>
- <div <?php post_class('post clear'); ?> id="post_<?php the_ID(); ?>">
- <?php if ( has_post_thumbnail() ) :?>
- <a href="<?php the_permalink() ?>" class="thumb"><?php the_post_thumbnail('thumbnail', array(
- 'alt' => trim(strip_tags( $post->post_title )),
- 'title' => trim(strip_tags( $post->post_title )),
- )); ?>
- <?php elseif ( ot_get_option('placeholder') != 'off' ): ?>
- <img src="<?php echo get_template_directory_uri(); ?>/img/thumb-small.png" alt="<?php the_title(); ?>" /></a>
- <?php endif; ?>
- <h2><a href="#" onclick="openbox('box-<?php the_ID(); ?>'); return false" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
- <div class="post-content"><?php if (function_exists('smart_excerpt')) smart_excerpt(get_the_excerpt(), 55); ?></div>
- <div id="best-info">
- <div id="buy"><a href="<?php $my_meta = get_post_custom_values( 'author-website', $ID ); if ( $my_meta) { foreach ( $my_meta as $val_key => $val_val ) echo $val_val; } ?>" title="<?php the_title(); ?>" target="_blank">Где купить</a></div>
- <div id="price">• <?php $my_meta = get_post_custom_values( 'product-price', $ID ); if ( $my_meta) { foreach ( $my_meta as $val_key => $val_val ) echo $val_val; } ?> руб</div>
- </div>
- <?php if (ot_get_option('excerpt-length') != '0'): ?>
- <div class="entry excerpt" id="box-<?php the_ID(); ?>" style="display: none;">
- <?php the_excerpt(); ?>
- <?php the_content(); ?>
- </div><!--/.entry-->
- <?php endif; ?>
- </div>
- <?php endwhile; ?>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement