Home>

Normal get using functionsget_previous_post ()andget_next_post ()not enough. Post typeprojectstores password-protected and archive fields as shown in the picture:

image

It is necessary to get the next \ previous post, provided that this post stores the value normal in the fieldACFI found the posts I needed and it turns out unsuccessfully to indicate that the next post should be from this list (probably by date it is better so that it does not lead to the same post).

public static function get_previous_normal_post (int $ current_post_id= null) {
    $ current_post_id= ($ current_post_id=== null) ?? get_the_ID ();
    $ query= new WP_Query ([
        'posts_per_page'= >
 -one,
        'post_type'= >
 'projects',
        'post_status'= >
 'publish',
        'meta_query'= >
 [
            'relation'= >
 'AND',
            'type'= >
 [
                'key'= >
 'type',
                'value'= >
 ['archive', 'commin_soon'],
            ],
        ],
        'post__not_in'= >
 [$ current_post_id],
    ]);
    wp_reset_postdata ();
    $ post_ids= wp_list_pluck ($ query->
posts, 'ID');
    print_r (get_previous_post (false, implode (',', $ post_ids)));
}