Home » Php » php – Category Page Filter WordPress

php – Category Page Filter WordPress

Posted by: admin February 25, 2020 Leave a comment

Questions:

I Have a Five Categories

  1. Category 1
  2. Category 2
  3. Category 3
  4. Category A
  5. Category B

My 1st Post has two categories Category 1, Category A
2nd Post has two categories Category 2, Category A

Now i am coming in 1st post detail Page click on Category A going to Category A now i want to show 1st Post Category A dont need 2nd post Category

can you Please Explain How to Filter Using WP_Query

$args = array(
    'numberposts' => -1,
    'post_type' => 'post',
    'tax_query' => array(
        array(
            'taxonomy' => 'category',
            'field' => 'term_id',
            'terms' => 'Category A',
        ),
    ),
    'orderby' => 'modified',
    'order' => 'DESC'
);
$myposts = new WP_Query($args);

Thanks in advance

How to&Answers: