query_posts has a construction with query_posts

 query_posts( array( 'post_type' => APP_POST_TYPE, 'meta_query' => array( array('key' => 'cp_category', 'value' => 'ะะต ะพะฟั€ะตะดะตะปะตะฝะพ', 'compare' => '=')), 'ignore_sticky_posts' => 1 ) ); get_template_part( 'loop', 'ad_listing' ); wp_reset_query(); 

On the first page, everything is displayed well, but pagination no longer works. I try to rewrite with replacement on get_posts like this, but some half-empty nonsense is displayed in the meta-data.

 $categories = get_posts( array( 'post_type' => APP_POST_TYPE, 'meta_query' => array( array('key' => 'cp_category', 'value' => 'ะะต ะพะฟั€ะตะดะตะปะตะฝะพ', 'compare' => '=')), 'ignore_sticky_posts' => 1 ) ); foreach( $categories as $$category ) { get_template_part( 'loop', 'ad_listing' ); } wp_reset_postdata(); ?> 

How to fix it and solve the problem with pagination?

    2 answers 2

    For pagination, you need the paged parameter and the number of posts on the page (the default is taken from the WordPress settings, but you can specify your own)

     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => APP_POST_TYPE, 'paged' => $paged, 'meta_query' => array( 'key' => 'cp_category', 'value' => 'ะะต ะพะฟั€ะตะดะตะปะตะฝะพ', 'compare' => '=' ), 'ignore_sticky_posts' => 1 ); $categories = get_posts( $args ); foreach( $categories as $category ) { get_template_part( 'loop', 'ad_listing' ); } wp_reset_postdata(); 
    • Sorry, but I can not plus, because. displays the list of exactly the same nonsense as with my version - Vasya
    • paged returns equal to 1 - John

    Pagination will work when the following condition is met:

    For getting the current page of the query page: Reference to the source.

     if ( is_front_page() ) { $paged = (get_query_var('page')) ? get_query_var('page') : 1; } else { $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; }