Jump to content

hw can i get drop down form to change sort by form asc or desc?


Lisa23

Recommended Posts

Hi i am trying to change the query to sort by desc or asc I am using the switch method but the form is not calling the switch statment can someone help me out please?

 

this is the swicth script

switch ($sortby) {
    case "ASC":
        	$args = array(
	's' => $_GET['s'],
	'post_type' => 'deals',
	'orderby' => 'title',
	'order' => 'ASC',
	'paged' => get_query_var('paged')
);
    break;
    case "DESC":
                	$args = array(
	's' => $_GET['s'],
	'post_type' => 'deals',
	'orderby' => 'title',
	'order' => 'DESC',
	'paged' => get_query_var('paged')
);
        break;
}

This is the form

<form name="myForm">
             <select id="sortby" > 
                 <option value="ASC">ASC</option>
                 <option value="DESC">DESC</option>
            </select>
         </form>

 

I intend to use a onchange so that when depending on the option they select it will change the order?

You would have to actually submit the form and then use the value of $_POST['sortby'] (note you'll need to give your select a name attribute) for your switch statement.

 

If you want to use the onchange event or otherwise do it without actually submitting the form you will have to use Javascript.

Hi thanks for getting back at me I managed to get it to work like this.

 

The script

switch ($_POST['sortby'])  { 
   case "ASC":
        	$args = array(
	's' => $_GET['s'],
	'post_type' => 'deals',
	'orderby' => 'title',
	'order' => 'ASC',
	'paged' => get_query_var('paged')
);
    break;
    case "DESC":
                	$args = array(
	's' => $_GET['s'],
	'post_type' => 'deals',
	'orderby' => 'title',
	'order' => 'DESC',
	'paged' => get_query_var('paged')
);
        break;


  }

 

The form

  <form method="post">
                                            <select name="sortby" onChange="this.submit()">
                                                <option value="">Sort By</option>
                                                <option value="DESC">DESC</option>
                                                <option value="ASC">ASC</option>
                                            </select>
                                            <input type="submit" value="submit">
                                        </form>

 

But now i am trying to change the form without the submit button just with the onchange. but is not working?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.