Remember to wrap your strings in quotes. I think that’s the main issue. This works for me:
<?php
// https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters
// Set up a new WP_Query object for posts that have the 'homepage' term
// set for the 'slider' taxonomy:
$slide_query = new WP_Query( array(
'posts_per_page' => 100, // Set a reasonable limit just in case.
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'slider', // Strings should have quotes!
'field' => 'slug',
'terms' => 'homepage',
),
),
));
?>
Then output the HTML:
<?php if ( $slide_query->have_posts() ) : ?>
<div class="slider">
<?php while ( $slide_query->have_posts() ) : $slide_query->the_post(); ?>
<div class="slide">
<h2 class="slide-title">><?php the_title(); ?></h2>
<div class="slide-content">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
</div>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
You don’t need to do the $temp = $wp_query; $wp_query= null;
thing. Just create a new variable like I did in the example, and call wp_reset_postdata()
as I did in the example.