I have been googling and having a look many other questions related to this one but the problem still persist.
I'm trying to get a paginated query and only page 1 is shown. If you change the paged variable to any other number, it returns an empty array.
Here is the code I used, that is very similar than others I've seen in other questions:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$temp = $wp_query;
$wp_query= null;
$args = array(
'posts_per_page' => 20,
'post_type' => 'post',
'paged' => $paged,
'category_name' => 'blog'
);
$wp_query = new WP_Query($args);
$data = array();
while ($wp_query->have_posts()) : $wp_query->the_post();
$obj = new stdClass;
$obj->id = $post->ID;
$obj->title = $post->post_title;
$obj->excerpt = substr(str_replace(array("\r","\t","\n"), array('','',''), trim(strip_tags($post->post_content))), 0, 200).'...';
$obj->slug = str_replace('http://localhost/', '', get_permalink($post->ID));
$obj->author_name = get_user_by('id', $post->post_author)->user_login;
$obj->featured_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'post-thumbnails') );
array_push($data, $obj);
endwhile;
What's wrong? I can not guess it!
page
instead of'paged
– Pierre