Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7847173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:48:33+00:00 2026-06-02T17:48:33+00:00

I have a form that allows a user to select a county from a

  • 0

I have a form that allows a user to select a county from a dropdown menu, My form is then posted to my functions.php page where I’ve been using IF statements to run my queries.

if ($_POST['dropdown1'] == 'option 1' && $_POST['dropdown 2'] == 'option 4' && $_POST['county'] == 'cheshire' ) {
    // RUN QUERY 
}       

My problem is however I can’t realistically use IF statements for every county in every possible scenario as there will be thousands of options, has anybody got a better idea of how I can do this?


if ($_POST['vehicleType'] == 'hgv' && $_POST['coverageRegion'] == 'national' ) {        

            $customkey = 'vehicleType'; 
            $customvalue = $_POST['vehicleType']; 

            $customkey1 = 'coverageRegion'; 
            $customvalue1 = $_POST['coverageRegion']; 

            $customkey2 = 'locationType'; 
            $customvalue2 = $_POST['locationType']; $args = array('orderby' => 'meta_value_num', 'meta_key' => 'order', 'order' => 'ASC',

            'meta_query' => array(
            array(
                'key' => $customkey,
                'value' => $customvalue,
                'compare' => '='
            ),
            array(
                'key' => $customkey1,
                'value' => $customvalue1,
                'compare' => '='
            ),
            array(
                'key' => $customkey2,
                'value' => $customvalue2,
                'compare' => '='
            )
            ) // end of array
            ); //end of if

            $query = new WP_Query( $args);





            // The Loop
                $i = 0; $i = -1;

while ( $query->have_posts() )
{
    $i++;
    $query->the_post();
    if ( $keys = get_post_custom_keys() )
    {
        echo "<div class='clearfix card-prod ".($i==0?'first':'')."'><div class='top-dets'><span class='card-title'>";
        echo the_title();
        echo "</span>";


    // Network query 
        $network_value = get_post_custom_values('srchnetwork');
        foreach ( $network_value as $key => $value ) {
        echo '<span class="srch-val-">'. $value . '</span>'; }// Pricing Query
        $pricing_value = get_post_custom_values('srchpricing');
        foreach ( $pricing_value as $key => $value ) {
        echo '<span class="srch-val-1">'. $value . '</span>'; }

    // Setup Query
        $setup_value = get_post_custom_values('srchsetupfee');
        foreach ( $setup_value as $key => $value ) {
        echo '<span class="srch-val-2">'. $value . '</span>'; }

    // Services Query
        $services_value = get_post_custom_values('srchservices');
        foreach ( $services_value as $key => $value ) {
        echo '<span class="srch-val-3">'. $value . '</span></div>'; }

    // Big Card Query
        $bigcard_value = get_post_custom_values('bigcard');
        foreach ( $bigcard_value as $key => $value ) {
             echo '<a href="/" class="cardclick"><img src="/wp-content/themes/CAFC/images/cards/'. $value . '" alt="'; }
     echo the_title() . '" /></a>';


    echo '<img src="wp-content/themes/CAFC/images/top-choice.jpg" alt="Top Choice" class="topchoice">';
echo the_excerpt()."</div>";   }
}

       }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:48:35+00:00Added an answer on June 2, 2026 at 5:48 pm

    You can write your code in this way so you don’t have to deal with every possible option.

    global $wpdb;
    
    $postKeys = array('vehicleType', 'coverageRegion', 'locationType');
    
    $args = array(
        'orderby' => 'meta_value_num',
        'meta_key' => 'order',
        'order' => 'ASC',
        'meta_query' => array()
    );
    
    foreach ($postKeys as $key) {
        $args['meta_query'][] = array(
            'key' => $key,
            'value' => $wpdb->escape($_POST[$key]),
            'compare' => '='
        );
    }
    
    $query = new WP_Query($args);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form on all my pages that allows the user to select
I have setup a form that allows a user to make selections from drop-down
I have a test application that allows the user to select a culture from
I have a django form that allows a user to select multiple options: CARDS
We have a form that allows a user to filter a list with by
I have a form that allows a user to import a spreadsheet. This spreadsheet
I have a product registration form that allows the user to add additional product
I have a bound form in microsoft access that allows a user to add
I have a typical ADO.NET EF-driven form that allows the user to input a
I have a form that once you select from a drop-down list and select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.