I have over 1000 posts with no tags. Basically I am trying to get posts with no tags to show in frontend so that users can add tags from frontend.
I am using this approach in loop so as to show posts with no tags.
<?php
$tag = get_the_tags();
if (! $tag) { ?>
<a href="<?php the_permalink();?>"><?php the_title() ?></a><br>
<?php }
?>
But is there a way so I can use WP_Query() itself so as to filter because $args are not applying properly with the above approach.
Thanks.
Full Code -
<?php
$args = array(
'post_type' => 'post',
);
$the_query = new WP_Query($args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php
$tag = get_the_tags();
if (! $tag) { ?>
<a href="<?php the_permalink();?>"><?php the_title() ?></a><br>
<?php }
?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
<?php wp_reset_query(); ?>