Categories:
php Wordpress

Complex arguments for WordPress WP_Query

01 October 2021
Author: victor-dev
$args = array(
	'post_type'              => array( 'news' ),
	'post_status'            => array( 'publish' ),
	'nopaging'               => false,
	'posts_per_page'         => '5',
	'ignore_sticky_posts'    => false,
	'order'                  => 'DESC',
	'orderby'                => 'date',
    'offset' => ($_GET['pageno'] * 5),
    $args['s'] => "test",

    'comment_count'  => array(
        'value'   => 0,
        'compare' => '=',
    ),
    
    'tax_query' => array(
    
        array(
            'taxonomy' => 'news_category',
            'terms' => 'social',
            'field' => 'slug',
            'include_children' => true,
            'operator' => 'IN'
        ), 
        array(
            'taxonomy' => 'news_type',
            'terms' => 'pozitive',
            'field' => 'slug',
            'include_children' => true,
            'operator' => 'IN'
        ), 
    ),
    'date_query' => array(
        array(
            'after'     => '01.01.2019',
            'before'    => '30.11.2019',
            'inclusive' => true,
        ),
    )
  
);
$the_query = new WP_Query( $args );