WorldTraffic
есть блог про трейлеры к фильмам, как сделать, что бы когда кликаешь на категорию, таг или поиск по блогу, то статьи сортировались по дате выхода фильма которая указывается при создании поста в дополнительном поле?
поле имеет свой идентификатор (тут я не уверен в правильности названия)
в файле loop-single.php
<?php if (get_post_meta($post->ID, 'review_release_rf_value', true)) { ?>
<div class="review-info-title">Премьера (РФ):</div>
<div class="review-info-data"><?php echo get_post_meta($post->ID, "review_release_rf_value", $single = true); ?></div>
<?php } ?>
и в файле functions.php
<?php
$post_custom_fields =
array(
"review_release_rf" => array(
"name" => "review_release_rf",
"std" => "",
"title" => "Премьера (РФ):",
"description" => ""
),
);
....
как сделать?
WorldTraffic
Yacc писал:
functions.php
Код:
function _sort($query) {
if( ! is_admin() && $query->is_main_query() && ($query->is_category() || $query->is_tag() || $query->is_search())) {
$query->set('order', 'DESC');
$query->set('orderby', 'meta_value_num');
$query->set('meta_key', 'review_release_rf');
}
}
add_action( 'pre_get_posts', '_sort' );
Будет работать при условии, что дата хранится в виде метки времени Unix.
перевел несколько дат в Unix, вставляю код(в верх файла functions.php после <?php ), сайт работает посты сортируются, только в админку попасть нельзя, перед входом такие ошибки
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 701
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 702
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 705
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 706
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 707
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 708
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 711
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 712
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 713
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 714
ввожу логин пароль и получаю белый лист с ошибками
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-login.php on line 362
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-login.php on line 374
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-login.php on line 376
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 680
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 681
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 682
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 684
Warning: Cannot modify header information - headers already sent by (output started at /var/www/data/www/domen.com/wordpress/wp-content/themes/domen/functions.php:1) in /var/www/data/www/domen.com/wordpress/wp-includes/pluggable.php on line 881
может не так вставляю?
вот так выглядит
<?php
function _sort($query) {
if( ! is_admin() && $query->is_main_query() && ($query->is_category() || $query->is_tag() || $query->is_search())) {
$query->set('order', 'DESC');
$query->set('orderby', 'meta_value_num');
$query->set('meta_key', 'review_unix_value');
}
}
add_action( 'pre_get_posts', '_sort' );
$post_custom_fields =
array(
"review_name" => array(
"name" => "review_name",
"std" => "",
"title" => "Название:",
"description" => ""
),
....