Display/Filter post using if else statement

The PHP while command doesn’t work like that, it needs to start and end in the same code block. You can’t start it inside one if then end it somewhere else (although that would be nice!)

What you can do is test have_posts before you start the while loop, and then keep which ever query you want in a new variable. So I think you want something like this. I’m assuming your two $post_cat and $post_tag searches do what you want for these two cases – i.e. $post_tag will be empty if there is nothing with this tag, and $post_cat gets what you want.

This code is untested but should do what you want. HTH

    <?php
    // Args to get what we want for the category
    $catArgs = array(
            'posts_per_page' => '1',
            'cat' => '3'
            );

    // Args to get one post with tag event
    $tagArgs = array(
            'posts_per_page' => '1',
            'cat' => '3',
            'tag' => 'event'
            );  
    
    $tagQuery = new WP_Query( $tagArgs );

    // if there's something in the tagquery we'll use it, otherwise we'll use the other query
    if ($tagQuery->have_posts()) {
        $loopQuery = $tagquery;
    } else { 
        $loopQuery = new WP_Query( $catArgs );
    }

    while ($loopQuery->have_posts()): $loopQuery->the_post();

    ?>
          <b>loop stuff here</b>
    <?php
    endwhile;
?>