I am attempting to construct a shortcode that can permit the person to decide on what class is displayed and what number of posts will present. The shortcode labored superb till I added the ‘tax_query’
add_shortcode( 'latest_post', 'latest_post_query_shortcode' );
perform latest_post_query_shortcode( $atts ) {
$atts = shortcode_atts( array(
'post_per_page' => '',
'class' => '',
), $atts );
$args = array(
'post_type' => 'submit',
'post_status' => 'publish',
'posts_per_page'=> 3,
'tax_query' => array( array(
'taxonomy' => 'class',
'area' => 'slug',
'phrases' => $classes
), ),
);
$string = '';
// The Question
$question = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) { ?>
<part class="recent-posts clear">
<?php whereas ( $query->have_posts() ) : $query->the_post() ; ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'left' ); ?>>
<? echo '<a href="' . get_permalink( $_post->ID ) . '" title="' . esc_attr( $_post->post_title ) . '">';
echo get_the_title( $_post->ID);
echo '</a>';
echo '<a href="' . get_permalink( $_post->ID ) . '" title="' . esc_attr( $_post->post_title ) . '">';
echo get_the_post_thumbnail( $_post->ID, 'medium' );
echo '</a>';
echo '<a href="' . get_permalink( $_post->ID ) . '" title="' . esc_attr( $_post->post_title ) . '">';
echo '<button>Learn Extra</button>';
echo '</a>';
?>
</article>
<?php endwhile; ?>
</part>
<?php } else {
echo 'No posts discovered';
}
/* Restore authentic Submit Knowledge */
wp_reset_postdata();
}
Earlier than including the tax_query, it might present the three newest posts, with the tax_query, it simply reveals “No posts discovered.” What am I doing improper right here?