Wordpress Post循环,带有搜索.php结果的查询$args


Wordpress Post loop with query $args on search.php results?

我正在创建一个搜索结果页面,我正在尝试排除特定的帖子格式。我找到了这个查询,但我不知道如何使 post 循环工作,我什至不知道代码。而且,我不知道如何将未找到的404错误放在搜索中.php。

这是代码

<?php
$args = array(
  'tax_query' => array(
    array(
      'taxonomy' => 'post_format',
      'field' => 'slug',
      'terms' => 'post-format-quote', 'post-format-video',
      'operator' => 'NOT IN'
    )
  )
);
query_posts( $args );
?>

我首先尝试了一些东西并且工作正常,但是如果我设置"每页 4 个帖子",它会计算所有格式的帖子,如果搜索结果中的标准帖子应该是 3 和 1 引用格式的帖子,它会显示 3 个标准帖子和一个空白区域。

<?php if ( have_posts() ) : ?>
 <?php while ( have_posts() ) : the_post(); ?>
<?php if( get_post_format() == 'quote' ) : ?>
<?php elseif( get_post_format() == 'link' ) : ?>
<?php elseif( get_post_format() == 'video' ) : ?>
<?php elseif( get_post_format() == 'image' ) : ?>
<?php else : ?>

post
<?php endif; ?>
<?php endwhile; else : ?>
    <?php get_template_part( 'partials/content', 'none' ); ?>
<?php endif; ?>
这是我

搜索的全部代码.php。这是不在我的搜索结果上显示其他格式帖子的唯一方法。我只是希望循环不在我的结果上计算"其他格式的帖子"。我想每页显示 4 个结果,并且必须是 4 个标准帖子格式。

  <?php
get_header(); ?>
<div id="content" class="site-content">

<div id="news-page">

<div class="right">

<?php get_sidebar(); ?>
</div>
<div class="left">
<div class="newstitle">RISULTATI</div>
<?php if ( have_posts() ) : ?>
 <?php while ( have_posts() ) : the_post(); ?>
<?php if( get_post_format() == 'quote' ) : ?>
<?php elseif( get_post_format() == 'link' ) : ?>
<?php elseif( get_post_format() == 'video' ) : ?>
<?php elseif( get_post_format() == 'image' ) : ?>
<?php else : ?>
<a href="<?php the_permalink(); ?>" title="Leggi">
<div class="post"> 
<div class="data">
<span class="giorno"><?php the_time('j M Y') ?></span> <span class="commenti"><?php comments_number('0 commenti', '1 commento', '% commenti'); ?></span>
</div>
<div class="thumb"><?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'news-page' ); } ?></div>
<div class="thumb-full"><?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'news-page-full' ); } ?></div>
<div class="title"><?php echo get_the_title( $post_id ); ?></div>
<div class="excerpt"><?php the_excerpt(); ?></div>
<div class="diss"></div>

<div style="position: absolute; z-index:999; bottom: 0; left: 0; font: normal 10px arial; padding: 3px;"> In <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></div>

</div>
</a>

<?php endif; ?>
<?php endwhile; else : ?>
    <?php get_template_part( 'partials/content', 'none' ); ?>
<?php endif; ?>
</div>
</div>

    </div><!-- #primary -->
<?php get_footer(); ?>