I have created a page template:

<?php /* Template Name: homedefault */ ?>

But Instead of text coming from here i.e. wp editor:

enter image description here

I want it to come from the loop:

   <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php $post_id = get_the_ID(); ?>
        <?php get_template_part('content','home'); ?>        
    <?php endwhile; ?>
    <?php endif; ?>

But the loop doesn't seem to be working. Is it possible at all?

P.S. → loop is for the posts →

enter image description here

  • Are you aware of the home.php template? – Tom J Nowell Feb 10 '18 at 11:41
  • Yes, and the home.php(and front-page.php) template is working fine with no issues, but I am creating them for some other purpose. – The WP Intermediate Feb 10 '18 at 11:44
  • Someone have downvoted me? May I know the reason why the post is downvoted. – The WP Intermediate Feb 10 '18 at 15:49
  • even moderators don't know who downvoted, but nobody is obligated to explain, it would be better to ask on the meta site why a question would be downvoted and how to improve it – Tom J Nowell Feb 11 '18 at 2:37
  • 1
    That's what the meta site is for, comments are for clarifying questions, by trying to discuss downvoting here you're hurting your own question and derailing. If you insist on it you must use the meta site, that is where discussion of the site and how to improve questions takes place. Not here. What you're asking could even be grounds for downvoting – Tom J Nowell Feb 11 '18 at 14:05

On your custom page template, the default loop is working and that's why the loop is fetching content from the page. You need a custom query in this case. Here's the code.

$query = new WP_Query( array(
    'post_type' => 'post',
    'post_status' => 'publish',
) );
if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        get_template_part( 'content', 'home' ); 
| improve this answer | |
  • Okies thanks for the input. Let me try that query I will update you. – The WP Intermediate Feb 10 '18 at 11:27
  • Thanks, I have accepted the answer. Now I will remember how to generate post loop on a static page. All the best for your WP journey. – The WP Intermediate Feb 10 '18 at 12:00
  • Is it you who have downvoted me? – The WP Intermediate Feb 10 '18 at 15:51
  • 2
    You accepted my answer and I got 3 upvotes and 1 upvote in a comment, then why would I downvote someone who helped me to get all these! I didn't do that man -_- – obiPlabon Feb 10 '18 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.