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 7767983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:48:25+00:00 2026-06-01T15:48:25+00:00

Hi Stack Overflow community. I’m developing a wordpress website for Satan. First of all,

  • 0

Hi Stack Overflow community.

I’m developing a wordpress website for Satan. First of all, I’m a junior webdeveloper, so let’s say that I still have a lot to learn… 🙂 This is the first time I’m working with Ajax, and I don’t have much experience with PHP or SQL outside wordpress.

This website has a search function based on checkboxes. I have 2 groups of 3 checkboxes (so, 6 in total). So, I have 2 taxonomies and each checkbox represents a different term. I want to change the contents of the page using ajax, based on the categories Satan chooses using these checkboxes. I was able to do this, but only for one combination of checkboxes at a time. Because there are dozens of different combinations, I don’t think that writing dozens of different queries/args (one for each combination) is a good policy. So, how can I do this?

Let’s see an example, for you to understand what I mean:

Imagine that Satan wants to check the number of souls in Hell trough a form. There’s two groups of checkboxes, one for people and one for punishments, something like this:

People

  • Men
  • Women
  • Children

Punishment

  • In flames
  • Impaled
  • Being eaten by demons

Now, I have this jQuery Ajax code:

$('#searchsouls').click(function(){
    $.ajax({
        url:"<?php echo get_bloginfo('template_url'); ?>/evil-laugh.php",
        type:"POST",
        async:"false",
        data:$("#de-form").serialize(),
        success:function(data) {
            $('#666').empty().html(data);
        },
        error:function(e){
            console.log('Error: ' + e);
        }
  });
  return false;
})

This is working just fine. Then, I have this code inside evil-laugh.php:

<?php global $query_string;
$args = wp_parse_args($query_string);
$args = array(
'post_type' => 'souls',
'paged' => $paged, 
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => -1,
'post_status' => 'publish',
);

?>

<!--  THE LOOP -->
<?php $wp_query = new WP_Query( $args ); ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

This, of course, shows all the souls and all kinds of punishments, nothing fancy. I know that I could accomplish what Satan wants by defining a different set of arguments for each combination of categories. Something like (suppose that the “Impaled” term has an ID of 9, and that “cat9” is the name of the checkbox):

if ($_POST['cat9']) {
$args = array(
'post_type' => 'souls',
'paged' => $paged, 
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => -1,
'post_status' => 'publish',
'punishment' => 'impaled',
);

However, there are dozens of different combinations. Here’s a few examples:

  • Men impaled
  • Women OR children being eaten by demons
  • Men OR women in flames OR impaled
  • Children in flames OR impaled OR being eaten by demons

I suppose I could do some sort of “for loop” to accomplish this, but I have no idea how to do this or how I could add the category IDs to the wordpress query, defining the respective ANDs and ORs.

I could really appreciate some help in this issue. However, have in mind that I don’t want just a solution, I want to understand what I’m doing and learn a few new things if possible.

Thanks in advance.

  • 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-01T15:48:27+00:00Added an answer on June 1, 2026 at 3:48 pm

    Well, I managed to find the solution myself. Not sure if it is the most robust solution for this kind of problem, but here goes in case someone is looking for the same thing.
    I changed the name of each checkbox to the name of the associated category, just for practical reasons. So, for example, for the “Men” checkbox I used name="Men", same for other categories. Here’s the code:

    if ($_POST['men']) {
        $args['people']='men';
    }   
    
    if ($_POST['women']) {
        if ($_POST['men']) {
            if ($_POST['children']) {
                $args['people']='men, women, children';
            } else {
                $args['people']='men, women';
            }   
        } else {
            $args['people']='women';
        }   
    }
    
    if ($_POST['children']) {
        if ($_POST['women']) {
            if ($_POST['men']) {
                $args['people']='men, women, children';
            } else {
                $args['people']='women, children';
            }   
        } elseif ($_POST['men']) {
            $args['people']='men, children';
        } else {
            $args['people']='children';
        }   
    }
    

    I have the same code for the punishments category, with different terms of course. I believe I still have some sort of redundancy on my code, but it works good. I will have to check that later. Sure this works fine for only 3 categories, if you have a lot of categories you won’t have a lot of fun programming like this, so it would be better to think about how to use a “for cycle” or similar. Cheers!

    UPDATE: New and better solution

    Finally I managed to get back to this project. Not only I managed to learn a bit more about PHP, the code is now much more robust and I can add as much category terms as I want. Here goes:

    $people_args = array(
        'type' => 'souls',
        'taxonomy' => 'people',
        'orderby' => 'name',
        'order' => 'ASC',
    );
    $people = get_categories($people_args);
    $arr_people = array();
    foreach ($_POST as $key => $value) {
       foreach($people as $person){
            if($person->slug == $key){
                array_push($arr_people, $key);
            }
       }            
    }
    $values_people = implode(",", $arr_people);
    $args['people']=$values_people;
    
    $punishment_args = array(
        'type' => 'souls',
        'taxonomy' => 'punishment',
        'orderby' => 'name',
        'order' => 'ASC',
    );
    $punishments = get_categories($punishment_args);
    $arr_punishment = array();
    foreach ($_POST as $key => $value) {
       foreach($punishments as $punishment){
            if($punishment->slug == $key){
                array_push($arr_punishment, $key);
            }
       }            
    }
    $values_punishment = implode(",", $arr_punishment);
    $args['punishment']=$values_punishment;
    

    Not sure if someone is interested in this, but here is my solution so far. This is a fully functional AJAX way to display contents by category, using checkboxes. As soon as the website is complete, I will place the URL here so you can test this code if you like.
    Knowledge is power.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings Stack Overflow community. I'm trying to make a function that can pop all
Stack Overflow. Let's say I want to initialize a non-static class of variables, two
Let me thanks you guys at the Stack Overflow community for helping me with
Let me first say that I realize this question is vague and does not
Hi stack overflow community. I have 2 dynamic divs that I want to float
I'm wondering what the Stack Overflow community thinks when it comes to creating a
I have some jQuery code contributed by another member of the stack overflow community
Hello Stack Overflow community, I'm in the process of learning WP7 development, I'm struggling
With the help of the Stack Overflow community I've written a pretty basic-but fun
Dear Stack Overflow Community, I have a question regarding how to incorporate a WHERE

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.