How can I get the first post THIS SAME CATEGORY? It's just that now he takes the very first post that is generally in this type, but it is necessary that he takes the first post in the same category as the last
if( get_adjacent_post(true, '', true) ) {
previous_post_link('%link', '<div class="navigation-portfolio-block"><h6 class="arrow-left mobile_navigation">Previous</h6></div> ');
} else {
$first = new WP_Query('post_type=portfolio&posts_per_page=1&order=DESC'); $first->the_post();
echo '<a href="' . get_permalink() . '">
How can I get the first post THIS SAME CATEGORY? It's just that now he takes the very first post that is generally in this type, but it is necessary that he takes the first post in the same category as the last
if( get_adjacent_post(true, '', true) ) {
previous_post_link('%link', '<div class="navigation-portfolio-block"><h6 class="arrow-left mobile_navigation">Previous</h6></div> ');
} else {
$first = new WP_Query('post_type=portfolio&posts_per_page=1&order=DESC'); $first->the_post();
echo '<a href="' . get_permalink() . '">
Share
Improve this question
asked Dec 23, 2019 at 13:46
KaizerKaizer
1
1 Answer
Reset to default 0You can use additional WP_Query parameters like post_per_page
For example,
$my_custom_query_args =
array( 'posts_per_page' =>1,
'orderby'=>'DESC');
$my_custom_query = new WP_Query( $my_custom_query_args );