Strange issue with WP_Query
-
So I’m trying to get 4 queries going on my index. They all work except one of them. It simply doesn’t show up even though I’ve copied all the other ones that do work and just changed the query name. I’m not getting post thumbnail or the_content or errors. Posting the code:
$args = array( 'post_type' => 'post', 'orderby' => 'rand', 'category_name' => 'venues', 'posts_per_page' => 1, 'paged' => $paged ); $venues = new WP_Query($args);
And here’s my loop:
<?php if ($venues->have_posts()) : while($venues->have_posts()) : $venues->the_post(); ?> <?php if(has_post_thumbnail()) { ?> <span class="item" style="background-image: url('<?php echo wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); ?>');"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> </a></span> <?php $trimtitle = get_the_title(); $shorttitle = wp_trim_words( $trimtitle, $num_words = 10, $more = '... ' ); echo '<h2><a href="' . get_permalink() . '">' . $shorttitle . '</a></h2>'; ?> <?php $content = get_the_content(); echo '<p>' . mb_strimwidth($content, 0, 270, ' ... ') . ' <a href=" ' . get_permalink() . ' ">more</a>' . '</p>'; ?> <?php } else echo '<span class="item" style="background-image: url(\'https://www.harshclimate.com/wp-content/uploads/2019/01/arizonaflag.jpg\');"><a href="' . get_the_permalink() . '" title="' . get_the_title() . '">' . ' ' . '</a></span>'; ?> <?php endwhile; else : '<p>Sorry, no venue posts have been added yet.</p>'; endif; wp_reset_postdata(); ?>
I do have a category named “Venues” and I do have posts attached to that category. Beyond all that, I have no idea why nothing under that query is showing up.
Viewing 13 replies - 1 through 13 (of 13 total)
Viewing 13 replies - 1 through 13 (of 13 total)
- The topic ‘Strange issue with WP_Query’ is closed to new replies.