How to check if a post exists in a particular category

0

I would like to know if you can help me, I am trying to check if there is any post in a certain category to do validation and if and then, but without much success so far.

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php if ( have_posts("cat=13") ) { ?>
<?php query_posts("cat=13&showposts=9&paged=$paged"); ?>

Sucesso

} else {

Falhou

?>
<?php } ?>   
<?php wp_reset_query();?>
    
asked by anonymous 23.11.2017 / 12:39

2 answers

0

Try to check if post_count is greater than 0. If yes, succeed. If not, you do not have a post.

More info: link

    
23.11.2017 / 12:54
0

Thank you for trying to help me, I have managed to solve it, if someone needs something similar, follow the code:

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php query_posts("cat=13&showposts=9&paged=$paged"); ?>
<?php if ( have_posts() ){ while ( have_posts() ) : the_post(); ?> 

Sucesso

} else {

Falhou

?>
<?php } ?>   
<?php wp_reset_query();?>
    
23.11.2017 / 13:12