V
V
Vadim Sverdlik2020-05-19 19:05:00
WordPress
Vadim Sverdlik, 2020-05-19 19:05:00

How to display the desired category of the post, bypassing the specific one?

I have the output of a post of a certain category (cat'=> 11), but the post has another category, and it is the main one, and it is its title and link to it that I need to display, but it displays the title and link of category 11, by which I display it. How can I make it display the main category of the post, bypassing category 11?

<?php $query2 = new WP_Query( array( 'posts_per_page' => 1, 'cat'=> 11 ) );?>
<?php if( $query2->have_posts() ){
while( $query2->have_posts () ){
$query2->the_post();

$cat = get_the_category();
$cat_ID= $cat[0]->term_id;
?>

<?php...





News of the day
<?= get_cat_name($cat_ID);?>


<?php the_title(); ?>


<?php }
wp_reset_postdata();
} ?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question