I'm creating a theme in which I've created a page template called page_default-blog.php to be used for creating a blog page. In this file I have the following code:
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array(
'paged' => $paged,
);
$custom_query = new WP_Query($args);
if ($custom_query->have_posts()) :
while($custom_query->have_posts()) : $custom_query->the_post(); ?>
the_title();
echo "<br>";
endwhile;
endif;
wp_reset_postdata();
The problem is that the sticky post doesn't come up at the top, even though the ignore_sticky_posts is set to false by default in $args.
The sticky post is showing at the top if I use the 'index.php' but it's not coming if I set the front page as the blog page.
Please let me know how I can get this to work. Thanks.
Edit 1:
Following is the result of var_dump ($custom_query->request);
:
string(217) "SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 4"
Edit 2:
This is what my template file page_default-blog.php
looks like:
<?php
/*
Template Name: Blog Default
*/
get_header();
wp_reset_postdata();
wp_reset_query();
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'ignore_sticky_posts' => 0,
);
$custom_query = new WP_Query( $args );
var_dump( $custom_query->is_home ); // This is returning bool(false)
?>
<div class="container">
<?php
if ($custom_query->have_posts()) : while($custom_query->have_posts()) : $custom_query->the_post(); ?>
<?php
echo the_title();
echo "<br>";
?>
<?php endwhile;
endif;
wp_reset_postdata();
?>
</div>
<?php get_footer(); ?>
The above is the exact file that I'm using right now. I simplified it to try to find the problem, but still haven't been able to, as the title for the sticky post is not appearing at the top of the list.