• Resolved powerj

    (@powerj)


    Hi,
    Hoping someone can help me with this loop. It works if a term is set. And if I manually change the $arg ‘tax_query’ => ” it works. But it shows no results as it is – I just don’t get it!

    function news_archive_loop() {
        global $post;
        $term = get_query_var(term);
         if (isset($term))
        {
            $tax_query[] =  array(
                    'taxonomy' => 'news-states',
                    'field' => 'name',
                    'terms' => $term
                );
        } else {
                    $tax_query =  '';
         }
    
       $args = array(
    		'post_type'      => 'news-article',
    		'posts_per_page' => 12,
    		'post_status'    => 'publish',
    		'paged'          => get_query_var( 'paged' ),
            'tax_query' => $tax_query
    
        );

Viewing 4 replies - 1 through 4 (of 4 total)
  • Discribe more info and use this short code.

    on $term single value arrived? if more then one pass with comma in array.
    'terms' => array('zyf','dasd');

    <?php
    function news_archive_loop() {
        global $post;
        $term = get_query_var(term);
        $args = array(
    		'post_type'      => 'news-article',
    		'posts_per_page' => 12,
    		'post_status'    => 'publish',
    		'paged'          => get_query_var( 'paged' ),
    		if (isset($term)){
    			'tax_query' => array(
    			array(
    					'taxonomy' => 'news-states',
    					'field' => 'name',
    					'terms' => $term
    				),
    			);
    		}
        );
    }

    Thread Starter powerj

    (@powerj)

    This returns unexpected if error.

    try this code below

    function news_archive_loop() {
        global $post;
        $term = get_query_var(term);
    
       $args = array(
    		'post_type'      => 'news-article',
    		'posts_per_page' => 12,
    		'post_status'    => 'publish',
    		'paged'          => get_query_var( 'paged' ),
            'tax_query' => $tax_query
    
        );
    	  if (isset($term))
        {
    		$args['tax_query'] = array(
                    'taxonomy' => 'news-states',
                    'field' => 'name',
                    'terms' => $term
                );
        }

    let me know if it works ?

    Thread Starter powerj

    (@powerj)

    many thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Help with WP Query args’ is closed to new replies.