WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] multiple queries sorted by url string (3 posts)

  1. jay.weeks
    Member
    Posted 4 years ago #

    I need to have multiple loops run on the index page sorted by category, this part is working. What isn't working is the preservation of sorting posts by tags called in the url string. This is the function I'm using to query posts by category:

    <?php
    function query_single_category($kat) {
    	$category_id = get_cat_id($kat);
    	query_posts($query_string . "&cat=$category_id");
    	if ( have_posts() ) : while ( have_posts() ) : the_post();
    	include("post-content.php");
    	endwhile;
    	else :
    	endif;
    }
    ?>

    This is how I'm calling specific categories in the template:
    <?php query_single_category('residential') ?>

    Any ideas why this isn't preserving the url string?
    I'm pretty sure my syntax is correct, I referenced the codex...would it have something to do with referencing the $query_string variable in functions.php?

  2. jay.weeks
    Member
    Posted 4 years ago #

    i just tested it, and inserting that code into the index template and $query_string worked.
    Now the issue is defining this variable for use in functions.php
    Any help?

  3. jay.weeks
    Member
    Posted 4 years ago #

    got it

    <?php
    function query_single_category($kat) {
    	$queryString = $_SERVER['QUERY_STRING'];
    	$category_id = get_cat_id($kat);
    	query_posts($queryString . "&cat=$category_id");
    	if ( have_posts() ) : while ( have_posts() ) : the_post();
    	include("post-content.php");
    	endwhile;
    	else :
    	endif;
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic