I trying to make a pagination links from my website.
Schema:
Serie | (category)
|_ Temporada 1 (taxonomy: temporada)
|_ Episodio 1 (posts 1 - meta_key: numeroepisodio)
|_ Episodio 2 (posts 2 - meta_key: numeroepisodio)
|_ Episodio 3 (posts 3 - meta_key: numeroepisodio)
|_ Episodio 4 (posts 4 - meta_key: numeroepisodio)
|_ ...
|_ Temporada 2 (taxonomy: temporada)
|_ Episodio 1 (posts 1 - meta_key: numeroepisodio)
|_ Episodio 2 (posts 2 - meta_key: numeroepisodio)
|_ Episodio 3 (posts 3 - meta_key: numeroepisodio)
|_ Episodio 4 (posts 4 - meta_key: numeroepisodio)
|_ ...
Another Serie 1
|_ ...
Another Serie 2
|_ ...
Problem:
When I create my posts, the pagination are order by DATE.
Can help me to make this order by meta_key, in same taxonomy only for current category?
Code:
<?php
$prev_post = get_adjacent_post( true, '', true );
$next_post = get_adjacent_post( true, '', false );
if ( !is_a( $next_post , 'WP_Post' ) ) {
$query_args = array (
'post_type' => 'post',
'posts_per_page' => -1,
'meta_key' => 'numeroepisodio',
'orderby' => 'meta_value meta_value_num',
'order' => 'DESC',
'paged' => $paged,
'tax_query' => array(
array( 'taxonomy' => 'categry'),
array( 'taxonomy' => 'temporada')
)
);
$oldest = get_posts($query_args);
$next_post = $oldest[0];
}
if ( !is_a( $prev_post , 'WP_Post' ) ) {
$latest = get_posts($query_args);
$prev_post = $latest[0];
}
?>
<?php if ( is_a( $prev_post , 'WP_Post' ) ) : ?>
<a href="<?php echo get_permalink( $prev_post->ID ); ?>"><div id="temporadas-dropdown"><i class="fa fa-caret-left"></i> ANTERIOR</div></a>
<?php endif; ?>
<?php if ( is_a( $next_post , 'WP_Post' ) ) : ?>
<a href="<?php echo get_permalink( $next_post->ID ); ?>"><div id="temporadas-dropdown">SIGUIENTE <i class="fa fa-caret-right"></i></div></a>
<?php endif; ?>
Here is a live example: http://series.enlatino.net/ver-online/silicon-valley/
Thanks so much in advice!
I found this:
from wordpress.stackexchange.com – which will explain it better, so check it out… the accepted answer, but essentially you might be able to alter the query with that filter, and there’s different filters – where, join, sort for both previous and next.
Totally different answer:
I am not really a fan of doing it manually but this might work – I did not test it though and my full understanding of taxonomies and the wordpress DB is somewhat lacking.
Call it:
$next_post = get_adjacent_episode($post, 'next');
$prev_post = get_adjacent_episode($post, 'previous');
Note that the query has only
select p.ID
, so you’d only be able to access$next_post->ID
but you could expand this select to capture more of the result if needed.