G
G
godsplane2020-05-01 12:22:52
WordPress
godsplane, 2020-05-01 12:22:52

Get_posts. Output tag outside the loop if there are posts of the specified type?

I send posts throughget_posts

spoiler
$lastposts = get_posts( array(
'numberposts' => $numberPost,
'tag' => $tag->slug,
'orderby'     => 'menu_order',
'order'       => 'DESC',
'post_type'   => 'video'
) );
?>
  <div class="video-wrapper">
    <?

if(have_posts(  )) {
  ?>
    <h2>qwe</h2>
    <?
}
  ?>

    <?
 foreach( $lastposts as $post ){ setup_postdata($post);
  
   ?>

    <div class="portfolio-item video-item">

      <div class="video-content">

        <?the_content();?>

      </div>
      <h2>
        <? the_title() ?>
      </h2>




    </div>

    <?php 
   
 }
 wp_reset_postdata();
 ?>

  </div>

In the line where if(have_posts( )) {I am trying to display the title of the post type, but it does not work, what construction should be applied here so that if there are posts with the video type, the h2 title is displayed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Neverov, 2020-05-01
@TTATPuOT

<?php if ($post->post_type == 'video'): ?>
  <h2>
    <? the_title() ?>
  </h2>
<?php endif; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question