1

I'm successfully was able to load this WP_Query to my Wordpress template-full-width-home.php (page One) file:

template-full-width-home.php

<?php
/*
Template Name: Full Width (No Sidebar) Homepage
*/

get_header(); ?>

<div class="content">
<div class="homeSlider">
<div class="containerSlide">
<h1 class="headHead">Heading</h1>
</div>
</div>  
<div class="inner-content grid-x grid-margin-x grid-padding-x home">
<main class="main small-12 medium-12 large-12 cell" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( 'parts/loop', 'page' ); ?>
<?php endwhile; endif; ?>

<div class="grid-x grid-padding-x blogsHome">
<?php 
// the query
$the_query = new WP_Query( array(
'posts_per_page' => 3,
'category_name' => '360 Themes!'
)); 
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?>
<div class="cell small-12 medium-6 large-4 singlePost">
<p><?php the_title(); ?></p>
<p><?php the_category(', '); ?></p>
<p><?php the_excerpt(); ?></p>
</div>
</div>
<script>
console.log("loaded");
</script>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?> 
<?php else : ?>
<p><?php __('No News'); ?></p>
<?php endif; ?>
</div>
</main> <!-- end #main -->
</div> <!-- end #inner-content -->
</div> <!-- end #content -->
<?php get_footer(); ?>

WP_Query of template-full-width-home.php

<?php 
// the query
$the_query = new WP_Query( array(
'posts_per_page' => 3,
'category_name' => '360 Themes!'
)); 
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query1->the_post(); ?>
 <?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?>
  <p><?php the_title(); ?></p>
  <p><?php the_category(', '); ?></p>
  <p><?php the_excerpt(); ?></p>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?> 
<?php else : ?>
<p><?php __('No News'); ?></p>
<?php endif; ?>

BUT when I try to load the same WP_Query into another template-full-width-home.php (page Two), I'm not able to get any results (nothing loads as it did on 'page One'). Any insight would be greatly appreciated!

template-full-width-home-es.php
<?php
/*
Template Name: Full Width (No Sidebar) Homepage ES
*/

get_header(); ?>

<div class="content">
<div class="homeSlider">
<div class="containerSlide">
<h1 class="headHead">Heading</h1>
</div>
</div>  
<div class="inner-content grid-x grid-margin-x grid-padding-x home">
<main class="main small-12 medium-12 large-12 cell" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( 'parts/loop', 'page' ); ?>
<?php endwhile; endif; ?>

<div class="grid-x grid-padding-x blogsHome">
<?php 
// the query
$the_query1 = new WP_Query( array(
'posts_per_page' => 3,
'category_name' => '360 Themes!'
)); 
?>
<?php if ( $the_query1->have_posts() ) : ?>
<?php while ( $the_query1->have_posts() ) : $the_query1->the_post(); ?>
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?>
<div class="cell small-12 medium-6 large-4 singlePost">
<p><?php the_title(); ?></p>
<p><?php the_category(', '); ?></p>
<p><?php the_excerpt(); ?></p>
</div>
</div>
<script>
console.log("loaded");
</script>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?> 
<?php else : ?>
<p><?php __('No News'); ?></p>
<?php endif; ?>
</div>
</main> <!-- end #main -->
</div> <!-- end #inner-content -->
</div> <!-- end #content -->
<?php get_footer(); ?>

WP_Query of template-full-width-home-es.php template

<?php 
// the query
$the_query = new WP_Query( array(
'posts_per_page' => 3,
'category_name' => '360 Themes!'
)); 
?>
 <?php if ( $the_query->have_posts() ) : ?>
  <?php while ( $the_query->have_posts() ) : $the_query1->the_post(); ?>
   <?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?>
    <p><?php the_title(); ?></p>
    <p><?php the_category(', '); ?></p>
    <p><?php the_excerpt(); ?></p>
  <?php endwhile; ?>
  <?php wp_reset_postdata(); ?> 
 <?php else : ?>
 <p><?php __('No News'); ?></p>
 <?php endif; ?>
7
  • Are you getting "No News" output on the new page you have created? Can I have the link of that page? Commented May 12, 2020 at 22:25
  • Not sure why its not displaying tbh Commented May 12, 2020 at 22:26
  • In the last section of code, i.e. "WP_Query of template-full-width-home-es.php template" you have used $the_query and $the_query1, maybe that's the issue. Do make it the same. Commented May 12, 2020 at 22:33
  • ya - i originally had them the same but changed them to see if that was the reason why it wasnt working. I've since changed them so that they're the same but still nothing works Commented May 12, 2020 at 22:38
  • Have you assigned the page template to that particular page? And how are you translating the page? Or is it a whole different site that the English version? Commented May 12, 2020 at 22:43

1 Answer 1

0

Please replace this section of code to debug the issue.

$the_query1 = new WP_Query( array(
'posts_per_page' => 3,
'category_name' => '360 Themes!'
)); 
print_r($the_query1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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