John Davidson

php - Previous post in WP_Query

0 comments
Message:


I have loop which displays a list of posts, the posts are displayed with sorting


 $query = new WP_Query([
'posts_per_page' => 3,
'post_type' => 'agency',
'meta_query' => array(

array(
'key' => 'date',
'value' => array( 0, 999 ),
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
),
),
'meta_key' => 'date',
'orderby' => 'meta_value_num',
'order' => 'ASC'
]);

I need to get the metadata of the previous post from the loop, I tried to do it like this


get_post_meta(get_previous_post()->ID, 'date', true);

But I am getting the previous post wrong, ignoring the arguments in WP_Query



My Answer:
10,
'order' => 'ASC',
'orderby' => 'date'
]);

Rate this post

3 of 5 based on 1414 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us