php - How to find untagged posts on WordPress?

542

i have some untagged posts , and i can't find an option that can list all my untagged posts so i can delete them .

i've read some article about that and they say that i need to do some change to wp_query , but i'm not familiar with php , i know some basic coding stuff but not php , i want someone to explain how i can do it , so i can list all my untagged posts

i found this code :

    $tag = get_the_tags();
if (! $tag) {
echo 'this post has no tags ' . /the_permalink();
}

i found it in : https://wordpress.org/support/topic/how-can-i-list-all-the-posts-that-have-0-tags?replies=5 , but the problem is 'm not familiar with php , so i don't know where to put the above code , can any one help ??

669

Answer

Solution:

That is not the best way to get posts that have no tags. Also notice the dates of the posts in that link - 7 years ago! That is definitely SIGNIFICANTLY out-of-date.

Have a look at this WordPress StackExchange post which shows you how to get retrieve tagless posts usingwp_query with thetax_query option: https://wordpress.stackexchange.com/questions/114978/get-all-posts-without-tags

$tags = get_terms('post_tag', array('fields'=>'ids') );
$args = array(
  'post_type' => 'post',
  'posts_per_page' => -1,
  'tax_query' => array(
    array(
      'taxonomy' => 'post_tag',
      'field' => 'id',
      'terms' => $tags,
      'operator' => 'NOT IN'
    )
  )
);
$untagged = new WP_Query( $args );

People are also looking for solutions to the problem: php - Laravel validator does not display messages after redirect?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.