按类别和后格式过滤

Filter on Category and Postformat

刚开始做Wordpress模板开发,慢慢习惯了

然而,我一直在寻找解决方案,但无法找到相同的问题。

我想过滤类别和 Post-格式,我有以下代码 Post 格式的过滤器有效,但不适用于类别。

$videos = new WP_Query( array(
'tax_query' => array(
    array(                
        'taxonomy' => 'post_format',
        'field' => 'slug',
        'terms' => array( 
        'post-format-video'
        ),
        'category_name=instructie-videos',
        'posts_per_page=6',
        'operator' => 'IN'
    )
)
) );
 $videos = new WP_Query( array(
 'post_type' => 'your-post-type',
 'posts_per_page' => 6,
 'category_name' => 'instructie-videos',
 'tax_query' => array(
      array(                
          'taxonomy' => 'post_format',
          'field' => 'slug',
          'terms' => array( 'post-format-video' ),
          'operator' => 'IN'
      )
    )
 ) );

可能是 category_name 附近的语法错误。试试上面的代码

你应该尝试如下:

$myposts = new WP_Query( array(
    'tax_query' => array(
        array(                
            'taxonomy' => 'post_format',
            'field' => 'slug',
            'terms' => array( 
                'post-format-aside',
                'post-format-audio',
                'post-format-chat',
                'post-format-gallery',
                'post-format-image',
                'post-format-link',
                'post-format-quote',
                'post-format-status',
                'post-format-video'
            ),
            'operator' => 'NOT IN'
        )
    )
) );