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

  • SEARCH
  • Home
  • 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 8124871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:36:40+00:00 2026-06-06T06:36:40+00:00

I have a client project that has posts assigned to their country of origin.

  • 0

I have a client project that has posts assigned to their country of origin.

The client wants to be able to search the posts by continent and or region.

I have a separate table that assigns each country to its respective region, and I have the WP query that uses the resulting array:

$country_names = array('England','France','Germany',...); // this would be the result from fetching countries associated with a region.
$args = array(
    'posts_per_page' => -1,
    'meta_query' => array(
        array(
            'key' => 'country',
            'value' => $country_names,
            'compare' => 'IN'
        )
    )
);
$query = new WP_Query( $args );

What I’m having trouble with is the part in the middle. Normally, I’d use some standard PHP/MySQL to craft the array:

<?php

//Process incoming variable
if(!empty($_REQUEST['region'])){
 $region = $_REQUEST['region'];
 } else {
 $region = NULL;
 }

// Make a MySQL Connection
$query = "SELECT * FROM regions WHERE region='$region'"; 

$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['country'];
?>

However, I’m having trouble making it work within a WP template, since WP manages the incoming variables using its own internal functions.

Can anyone help me to connect the two together? I’m sure I’m overlooking some simple step here, or else I’m not using some built-in WP function.

Any help is appreciated.

Thanks!

ty

  • 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-06T06:36:42+00:00Added an answer on June 6, 2026 at 6:36 am

    Add this in your functions.php

    add_filter( 'query_vars', 'addnew_query_vars', 10, 1 );
    function addnew_query_vars($vars)
    {   
        $vars[] = 'region'; // region is the variable you want to add       
        $vars[] = 'anotherVar'; 
        return $vars;
    }
    

    Then get it

    $region=get_query_var('region')
    

    Update

    $regions = $wpdb->get_results("SELECT ".$region." FROM `".$wpdb->regions."`");
    if($regions)
    {
        foreach($regions as $region)
        {
            // your code
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a client that has Oracle Standard , and a project that would
I have a Maven based Spring-WS client project that I want to package as
We have a Flex client and a server that is using the Spring/Blazeds project.
We have a base product that has bespoke development for each client that extends
I have a web service project that has 2 asmx files. Let’s call them
i am doing a project that will have multiple channels for clients chatting. Each
I have rich client platform project. To ramble through source code I have download
I have Client-Server environment and developed a project for Client-Server. I need to share
Hope I'm asking this correctly: I have a project Projects.Client I have my class
Currently, I'm working on a project where I have a server - client relationship

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.