How to check if there is a post in a certain category

Asked

Viewed 300 times

0

I wonder if you can help me, I’m trying to check if there is any post in a certain category to do validation and if and esle, however 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();?>
  • When you say a post, is if you received any data via post ? , if that’s so if(!empty($_POST['cat'])) { //tem post }

  • Not some data but literally the post

  • Try to show an example of how the result would be if you have a post or when you don’t, which is easier to validate

  • If there is a post in a certain category it displays the normal post, but if there is no post in that category it displays an image stating that it is still in deployment

2 answers

0

  • I’m trying to utilize already return with what happened

  • I did, but I did it another way was just add a { in my code in the right place to work

0

Thank you for trying to help me, I’ve already solved, in case someone needs something like that, 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();?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.