• Resolved Rimfya

    (@rimfya)


    Have Googled high and low for an answer to this one. I want to pass on multiple values to use as variables on a page that then shows posts that match those variables. I cannot work out how to add more than one variable to the URL though in functions.php

    So at the moment I have this working https://example.com/?minBeds=1 but I want to build the URL out to something like https://example.com/?minBeds=1&maxBeds=4

    Using this one works…

    function add_query_vars_filter( $vars ){
      $vars[] = "minBeds";
      return $vars;
    }
    add_filter( 'query_vars', 'add_query_vars_filter' );

    But obviously I’d like to add maxBeds, minPrice, maxPrice etc.

    Help please!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try adding the other values the same as you did for “minBeds”:

    function add_query_vars_filter( $vars ) {
    
    	$vars[] = "minBeds";
    	$vars[] = "maxBeds";
    	$vars[] = "minPrice";
    	$vars[] = "maxPrice";
    
    	return $vars;
    }
    add_filter( 'query_vars', 'add_query_vars_filter' );

    Or try it like this:

    function add_query_vars_filter( $vars ) {
    
    	$new_vars = array( 'minBeds', 'maxBeds', 'minPrice', 'maxPrice' );
    	$vars = array_merge( $vars, $new_vars );
    
    	return $vars;
    }
    add_filter( 'query_vars', 'add_query_vars_filter' );

    Thread Starter Rimfya

    (@rimfya)

    UH-MAZING.

    Thank you, knew it had to be simple!

    Thread Starter Rimfya

    (@rimfya)

    Oh, and solved.

    Whenever I add something like above to my functions.php page, I get this:

    Fatal error: Call to undefined function add_filter() in /home4/jwrbloom/public_html/eg10basketball.com/wp-includes/functions.php on line 33

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Multiple Query Values in URL’ is closed to new replies.