• Resolved inspirizone

    (@inspirizone)


    Hi guys,
    I have a javascript script that write a url including queries for filters, so when pressed, those queries are applied. This is used in combination with the following php code;

    <?php  
    
    	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    	if( !empty($_GET['orderby']) ) $orderby=$_GET['orderby'];
    	else $orderby = 'Date'; // default
    	if( !empty($_GET['tag']) ) $tags=$_GET['tag'];
    	else $tags = ''; // default
    	if( !empty($_GET['colours']) ) $colours=$_GET['colours'];
    	else $colours = ''; // default
    	if( !empty($_GET['category_name']) ) $catname=$_GET['category_name'];
    	else $catname = ''; // default
    	if( !empty($_GET['author']) ) $author=$_GET['author'];
    	else $author = ''; // default	
    
    $args = array(
          'meta_key' => '_post_like_count',
          'orderby' => $orderby,
          'category_name' => $catname,
          'tag' => $tags,
          'colours' => $colours,
          'author' => $author,
          'paged' => $paged
        );
    ?>

    This all works amazingly, yet when I only activate 1 category,
    i.e the url is index.php/?orderby=date&order=DESC&category_name=Graphics the query grabs all posts from the blog.
    This does not happen when I activate 2 categories, it grabs both categories posts.
    Does anyone know why this is happening?

Viewing 1 replies (of 1 total)
  • Thread Starter inspirizone

    (@inspirizone)

    Solved, the code above takes the URL and turns it into a query, and for category_name, if only 1 was used, the wordpress rewrite would swap the category_name=cat for /category/cat so I solved this by putting an empty dummy in, so the url always had two categories, one an empty one.

Viewing 1 replies (of 1 total)
  • The topic ‘WP query 'category_name' not working when 1 category selected’ is closed to new replies.