繁体   English   中英

Wordpress - 按自定义字段分类的单一导航顺序

[英]Wordpress - Taxonomy single navigation order by custom field

我这里有问题。

我喜欢在single.php 中显示 2 个导航按钮,基于分类法(税名: temporada

现在我谷歌它。 我找到了一个简单的代码来显示这个按钮,但是,这是按日期排序的,我喜欢订购这个,但是自定义字段(自定义字段: numeroepisodio

这是我的代码:

函数.php

add_filter( 'get_next_post_join', 'navigate_in_same_taxonomy_join', 20);
add_filter( 'get_previous_post_join', 'navigate_in_same_taxonomy_join', 20 );

function navigate_in_same_taxonomy_join() {
    global $wpdb;
return " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.    term_taxonomy_id = tt.term_taxonomy_id";
}

add_filter( 'get_next_post_where' , 'navigate_in_same_taxonomy_where' );
add_filter( 'get_previous_post_where' , 'navigate_in_same_taxonomy_where' );

function navigate_in_same_taxonomy_where( $original ) {
    global $wpdb, $post;
    $where = '';
    $taxonomy   = 'temporada';
    $op = ('get_previous_post_where' == current_filter()) ? '<' : '>';
    $where = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
        if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) )
    return $original ;

    $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
    $term_array = array_map( 'intval', $term_array );

        if ( ! $term_array || is_wp_error( $term_array ) )
    return $original ;
    $where = " AND tt.term_id IN (" . implode( ',', $term_array ) . ")";
return $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $where", $post->    post_date, $post->post_type );
}

单个.php

<?php if ( get_previous_post() != null ) : ?>
<?php
$singular_nav_previous_text = apply_filters( 'tc_singular_nav_previous_text', _x( '&larr;' , 'Previous post link' , '    customizr' ) );
    previous_post_link( '%link' , '<div id="temporadas-dropdown"><i class="fa fa-caret-left"></i> ANTERIOR</div>' );
?>
<?php endif; ?>

<?php if ( get_next_post() != null ) : ?>
<?php
$singular_nav_next_text = apply_filters( 'tc_singular_nav_next_text', _x( '&rarr;' , 'Next post link' , 'customizr'     ) );
    next_post_link( '%link' , '<div id="temporadas-dropdown">SIGUIENTE <i class="fa fa-caret-right"></i></div>' );
?>
<?php endif; ?>

如何显示基于taxonomy = 'temporada'和 order by meta_value = 'numeroepisodio'

谢谢你的时间。

为什么不使用 WP_Query 对象,如下所示

$posts = get_posts(array(
    'post_type'         => 'post',
    'posts_per_page'    => -1,
    'orderby'           => 'numeroepisodio',
    'order'             => 'DESC',
    'tax_query' => array(
                     array(
                           'taxonomy' => 'temporada' 
                           )
));

if( $posts ): ?>

// Do something here

<? endif;

您可能需要稍微修改它并检查语法..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM