- This topic has 3 replies, 2 voices, and was last updated 3 years, 2 months ago by Tom.
-
AuthorPosts
-
February 4, 2021 at 10:50 pm #1646450Jorian
Hello,
I’ve created a page where i use an element to loop a CPT archieve
When i set this page as homepage, the loop is not working.This code do i use:
<?php $args = array( 'post_type' => 'woningen' ); $the_query = new WP_Query($args); ?> <?php if ($the_query->have_posts() ) : while ($the_query->have_posts() ) :$the_query->the_post(); ?> <!-- hero-area-start--> <div class="hero-area"> <div class="hero-left1"> <div class="hero-left-box"> <div class="hero-box-title"> <h3><a href="<?php the_permalink(); ?>"><?php the_field('adres'); ?>, <?php the_field('plaats'); ?></a><span class="hero-box-status"><?php the_field('verkocht'); ?></span></h3> <a href="<?php the_permalink(); ?>">€ <?php the_field('prijs'); ?>,- kk</a> </div> <div class="hero-box-containt-fl"> <div class="hero-img"><?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail( 'full' ); } ?></div> <div class="hero-containt"> <div class="hero-single-text"> <h3>Bouwjaar: <?php the_field('bouwjaar'); ?></h3> <h3>Inhoud: <?php the_field('inhoud'); ?> m3</h3> </div> <div class="hero-single-text"> <h3>Eigen grond: <?php the_field('eigen_grond'); ?> m2</h3> <h3>Slaapkamers: <?php the_field('slaapkamers'); ?></h3> </div> <div class="hero-single-text-details"> <p><?php the_field('beschrijving'); ?></p> </div> </div> </div> <div class="hero-left-btn"> <a href="<?php the_permalink(); ?>">Foto’s</a> <a href="<?php the_field('video'); ?>" target="_blank">Video</a> <a href="<?php the_permalink(); ?>#plattegrond">Plattegrond</a> <?php $file = get_field('brochure'); if( $file ): ?> <a href="<?php echo $file['url']; ?>" target="_blank">Brochure</a> <?php endif; ?> </div> </div> </div> </div> <!-- hero-area-end--> <?php endwhile; ?> <?php endif; ?>
February 5, 2021 at 9:09 am #1647256TomLead DeveloperLead DeveloperHi there,
Does it output anything at all?
The fact the page already has a query is likely the issue. What if you reset the query before your custom query?: https://developer.wordpress.org/reference/functions/wp_reset_query/
February 6, 2021 at 1:07 am #1647777JorianHello Tom,
The page outputs only sidebar and navigation.
I put your code in my element, but i cannot see any change.
When i put it to functions.php i get an error:
Fatal error: Cannot redeclare wp_reset_query() (previously declared in /home/siebe/domains/waaijeradvies.nl/public_html/wordpress/wp-includes/query.php:114) in /home/siebe/domains/waaijeradvies.nl/public_html/wordpress/wp-content/themes/generatepress_child/functions.php on line 10
February 6, 2021 at 10:30 am #1648413TomLead DeveloperLead DeveloperThe code you add should just look like this:
wp_reset_query();
If that doesn’t work, you will likely need to build a custom page template and completely replace the default query with your own.
-
AuthorPosts
- You must be logged in to reply to this topic.